12 html javascript css jquery
我需要创建一个可滚动的div,即使鼠标位于内容(可滚动div内),也不仅仅是它旁边(它在空白处),滚动.这是我到目前为止:
var main = document.getElementById('main-site');
var maxTop = main.parentNode.scrollHeight-main.offsetHeight;
main.parentNode.parentNode.onscroll = function() {
main.style.top = Math.min(this.scrollTop,maxTop) + "px";
}
Run Code Online (Sandbox Code Playgroud)
在Chrome浏览器中没问题在IE8 +中确定(我知道一个黑客)在Safari中,当我滚动时,内容会震动很多,我可以解决这个问题吗?(我想解决这个问题)
工作小提琴 - > https://jsfiddle.net/8oj0sge4/6/
var main = document.getElementById('main-site');
var maxTop = main.parentNode.scrollHeight - main.offsetHeight;
main.parentNode.parentNode.onscroll = function() {
main.style.top = Math.min(this.scrollTop, maxTop) + "px";
}Run Code Online (Sandbox Code Playgroud)
#wrapper {
width: 100%;
height: 1500px;
border: 1px solid red;
padding-top: 380px;
}
#wrapper .container {
border: 1px solid green;
width: 100%;
height: 500px;
overflow: scroll;
}
#wrapper .container-scroll {
height: 1500px;
width: 100%;
border: 1px solid yellow;
position: relative;
}
#wrapper .main {
width: 200px;
height: 500px;
background: black;
overflow: scroll;
position: absolute;
color: white;
left: 50%;
margin-left: -100px;
margin-top: 10px;
}Run Code Online (Sandbox Code Playgroud)
<div id="wrapper">
<div class="container">
<div class="container-scroll">
<div id="main-site" class="main">
My goals is to make the div container scroll also when the mouse is hover this div in safari, in Google and IE8 i already know how to make work, but safari is shaking a lot!
</div>
</div>
</div>
</div>Run Code Online (Sandbox Code Playgroud)
感谢你们.
我希望这个演示可以帮助你在鼠标悬停和鼠标离开div时使div内容滚动.
<html>
</head>
<style>
.mydiv
{height: 50px;width: 100px; overflow-y: scroll; }
</style>
<script>
function loadpage()
{ document.getElementById('marquee1').stop(); }
function marqueenow()
{ document.getElementById('marquee1').start(); }
</script>
</head>
<body onload="loadpage()">
<marquee id="marquee1" class="mydiv" onmouseover="marqueenow()" onmouseout="loadpage()" behavior="scroll" direction="up" scrollamount="10">
This is my test content This is my test content This is my test content This is my test content This is my test content This is my test content This is my test
content This is my test content This is my test content This is my test content This is my test content This is my test content This is my test content This is my test content This is my test content This is my test content
</marquee>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
不是 100% 确定你在做什么,但你可以使用 css“fixed”获得固定位置。它会留在您放置的位置。以下 css 修复到页面底部。
.fixed {
bottom: 0;
left: 0;
position: fixed;
right: 0;
top: auto;
}
Run Code Online (Sandbox Code Playgroud)
关于滚动位置已经有一个答案: How to getscrollbarposition with Javascript?