javascript - Same code acts differently on website and jsfiddle -
i have code meant allow user scroll sideways clicking, works on jsfiddle, different on actual website. on website, can scroll right once no further, , when scroll back, apparently scrolls right past left-hand border.
here's live link problem on website: rouvou.com/error
and here's fiddle.
i literally copied , pasted code. i'm using jquery 1.10.0 on website , closest jquery version jsfiddle has 1.10.1, can't imagine cause different behavior. html posted code on entire page. on both locations, i'm using chrome version 42.0.2311.152 (64-bit) on ubuntu.
why might code have different results on jsfiddle , website?
$(document).ready(function() { var $item = $('div.item'), //cache dom selector visible = 2, //set number of items visible index = 0, //starting index endindex = ($item.length / visible) - 1; //end index $('div#arrowr').click(function() { if(index < endindex) { index++; $item.animate({ 'left': '-=300px' }); } }); $('div#arrowl').click(function() { if(index > 0) { index--; $item.animate({ 'left': '+=300px' }); } }); });
#container { width: 340px; height: 50px; } #list-container { overflow: hidden; width: 300px; float: left; } .list { background: grey; min-width: 1400px; float: left; } #arrowr { background: yellow; width: 20px; height: 50px; float: right; cursor: pointer; } #arrowl { background: yellow; width: 20px; height: 50px; float: left; cursor: pointer; } .item { background: green; width: 140px; height: 40px; margin: 5px; float: left; position: relative; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script> <div id="container"> <div id="arrowl"> </div> <div id="arrowr"> </div> <div id="list-container"> <div class='list'> <div class='item'>1 </div> <div class='item'>2 </div> <div class='item'>3 </div> <div class="item">4 </div> <div class='item'>5 </div> <div class='item'>6 </div> <div class='item'>7 </div> <div class="item">8 </div> </div> </div> </div>
it seems said, 1.10.0
has bug on that. created altered version of jsfiddle, difference jquery using version 1.10.0
, can see works site now.
see jquery 1.10.1 change log :
- effects
#13937: finish() finishes last item of set being .animate()d.
#13939: 1.10.0 breaks relative animation
and issue ticket#13939 :
- description
relative animation (using += or -=) broken in 1.10.0. example, $('h1').animate({marginleft: '+=100px'}); not work.
so, might have switch version 1.10.x
x
latest version, change should issue fixes, not functionality changes.
Comments
Post a Comment