最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - horizontal scroll on clicking button - Stack Overflow

programmeradmin1浏览0评论

I want to horizontally scroll a div by clicking on the button Left and Right but it is not working

$('#left').live('click' , function(){
$('#myDiv').scrollLeft(300)

})
$('#right').live('click' , function(){
$('#myDiv').scrollLeft(-300)

})

​ How can I scroll a div by a bytton click. I also want to remove the scroll bar

JS Fiddle

I want to horizontally scroll a div by clicking on the button Left and Right but it is not working

$('#left').live('click' , function(){
$('#myDiv').scrollLeft(300)

})
$('#right').live('click' , function(){
$('#myDiv').scrollLeft(-300)

})

​ How can I scroll a div by a bytton click. I also want to remove the scroll bar

JS Fiddle

Share Improve this question asked Jun 25, 2012 at 8:11 Muhammad UsmanMuhammad Usman 11k22 gold badges75 silver badges109 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

If you don't want to get rid of the scroll bars, why don't you just alter the CSS of the cropped content (i.e. its margin-left)?

Give the wrapping div a overflow:hidden and use the following JS:

$('#left').click(function(){
    $('#myDiv').css('margin-left','-300px');
});
$('#right').click(function(){
    $('#myDiv').css('margin-left','0');
});

Would look like this.

Is this what you want?

jsfiddle

i used css and margins for scroll, overflow hidden to hide the bar, float to align the pictures and changed some css...

发布评论

评论列表(0)

  1. 暂无评论