阻止图像堆叠?
我正在制作一个小 jQuery 插件,为图像和内容创建滑块。然而,为图像/内容生成的跨度堆叠在另一个之上并垂直溢出,而不是彼此相邻并水平溢出。我已经尝试了多种使用 css 的方法,但它不起作用...我使用的代码如下:
<!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>Untitled Document</title>
<!--<script src="http://code.jquery.com/jquery-latest.min.js"></script>-->
<script src="jquery.js"></script>
</head>
<body>
<script type="text/javascript">
(function($) {
$.fn.slider = function(options) {
var settings = {
'delay': '5',
'height': '500px',
'width': '500px',
'anim': 'slide',
'slidedir':'right',
};
var options = $.extend(settings, options);
return this.each(function() {
var o = options;
var slidenum=0;
$(this).hide();
$(this).before('<div id="jqueryslider" style="overflow:scroll;max-height:'+o.height+';height:'+o.height+';width:'+o.width+'"></div>');
$(this).find('li').each(function(){
slidenum++;
var title=$(this).attr('title');
var html=$(this).html();
$('#jqueryslider').append('<span class="slidercont">'+html+'</span>');
$('.slidercont img').css('width',o.width).css('height',o.height);
});
});
};
})(jQuery);
$(document).ready(function(){
$('#slider').slider();
});
</script>
<ul id="slider">
<li title="Tulips"><img src="Tulips.jpg" /></li>
<li title="Penguin"><img src="Penguins.jpg" /></li>
</ul>
</body>
</html>
重要! IT 与li
无关。这些仅用于组织目的。实际显示的内容是在 spans
中,其中包含 li
的 html。运行脚本时,UL
和 LI
会被隐藏。
I'm making a little jQuery plugin that creates a slider for images and content. However, the spans generated for the images/content are stacking ontop of another and overflowing vertically instead of sitting beside each other and overflowing horizontally. I've tried numerous ways using css and it doesn't work... The code I'm using is below:
<!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>Untitled Document</title>
<!--<script src="http://code.jquery.com/jquery-latest.min.js"></script>-->
<script src="jquery.js"></script>
</head>
<body>
<script type="text/javascript">
(function($) {
$.fn.slider = function(options) {
var settings = {
'delay': '5',
'height': '500px',
'width': '500px',
'anim': 'slide',
'slidedir':'right',
};
var options = $.extend(settings, options);
return this.each(function() {
var o = options;
var slidenum=0;
$(this).hide();
$(this).before('<div id="jqueryslider" style="overflow:scroll;max-height:'+o.height+';height:'+o.height+';width:'+o.width+'"></div>');
$(this).find('li').each(function(){
slidenum++;
var title=$(this).attr('title');
var html=$(this).html();
$('#jqueryslider').append('<span class="slidercont">'+html+'</span>');
$('.slidercont img').css('width',o.width).css('height',o.height);
});
});
};
})(jQuery);
$(document).ready(function(){
$('#slider').slider();
});
</script>
<ul id="slider">
<li title="Tulips"><img src="Tulips.jpg" /></li>
<li title="Penguin"><img src="Penguins.jpg" /></li>
</ul>
</body>
</html>
IMPORTANT! IT has nothing to do with the li
's. Those are only there for organizational purposes. The actual thing that is displayed is in spans
that have the html of the li
's. The UL
and LI
's are hidden when the script is run.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
此时的其他答案只是查看 pre-js HTML 标记。 post-jquery 标记完全不同,因此这些无法解决您的问题。
.slidercont
包装器从更改为
;
display: inline-block;
到.slidercont
string
更改为int
代码> (没有“px”,将其添加到函数中)#jqueryslider
的宽度设置为options.width * slipnum
这就是我通常使用滑块解决此问题的方法。收藏了这个,以便我看看我是否做错了......
The other answers at this point are just looking at the pre-js HTML markup. The post-jquery markup is quite different, so those won't fix your problem..
.slidercont
wrapper from<span>
to<div>
display: inline-block;
to.slidercont
int
fromstring
(no 'px', added that to function)#jqueryslider
tooptions.width * slidenum
This is how I usually approach this problem with sliders. Favorited this so I can see if I'm doing this wrong...
将
display: inline;
添加到中。列表项默认堆叠(它们具有
display: list-item
)。Add
display: inline;
to the<li>
s. List items are stacked by default (they havedisplay: list-item
).您应该尝试使用
标签使用此 CSS:
我希望这会有所帮助。
You should try this CSS for the
<li>
tags:I hope this helps.