[英]Dynamic left attr issue on Internet Explorer 11
$('div').css('left' ,$("id").scrollLeft());},
我尝试使用此代码为div
赋予left
属性,该属性会根据scrollLeft
函数而变化。 它在chrome上完美运行,但是每当我拖动水平滚动条时,内容就会在Internet Explorer上滑动。
关于如何解决它的任何想法?
这是我使用的代码,可在Chrome和IE 11中使用
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function () {
$("button").click(function () {
alert($("#test1").scrollLeft() + " px");
$('#test2').css('left', $("#test1").scrollLeft());
});
$(window).scroll(function () {
$('#test2').css({ 'left': 20 + $(this).scrollLeft() + 'px' });
});
});
</script>
<style>
div {
border: 1px solid black;
width: 100px;
height: 100px;
overflow-x: scroll;
overflow-y: scroll;
}
</style>
</head>
<body>
<div style="width:1000px;">
<div id="test1">
<div style="width:200px;">
#test1 - Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello
</div>
</div>
<br>
<button>Click Here!</button>
<div id="test2" style="position:absolute;">
#test2
</div>
</div>
</body>
</html>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.