`
axl234
  • 浏览: 259411 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

css实现图片根据鼠标滚轮滚动

    博客分类:
  • css
 
阅读更多

实现新浪微博图片浏览的功能 在一个div内显示一个比div内容高的图片,当想看到图片其他部分时可以通过滚轮实现上下滚动图片。

原理:嵌套2层div内层的高度固定overflow:scroll;这样会显示滚动条,然后让外层的div宽高小一点overflow:hidden;刚好把滚动条的部分隐藏掉,这样就可以实现无滚动条的滚动了

具体代码如下:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无滚动条的图片滚动</title>
<style type="text/css">
*{ margin:0; padding:0}
.outer{width:400px; height:280px; margin:0 auto; border:1px solid #33F; overflow:hidden; background:#9C0; text-align:center;}
.mousewheel_example{ width:420px; height:300px; margin:0 auto; overflow:scroll; font-size:12px; color:#F00; text-align:center;}
</style>
</head>
<body>
<br /><br/><br /><br/><br /><br/>
<div class="outer">
<div class="mousewheel_example">
<img src="images/w.jpg" />
</div>
</div>
</body>
</html>

0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics