javascript Unslider 无法在网站上运行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17382355/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unslider not working on website
提问by Ryman Holmes
This http://unslider.com/for some reason is not appearing on my site, only the li
text is showing and it is sliding but there is no appearance of the slider, just the text.
这个http://unslider.com/由于某种原因没有出现在我的网站上,只显示li
文本并且它正在滑动,但没有滑块的外观,只有文本。
I have included the js
files along with the css and markup but its somehow not showing me the full slider.
我已经包含了这些js
文件以及 css 和标记,但它以某种方式没有向我显示完整的滑块。
Here is my code:
这是我的代码:
HTML:
HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Webpage</title>
<link rel = "stylesheet" type = "text/css" href = "1style.css"/>
<script src="//code.jquery.com/jquery-latest.min.js"></script>
<script src="//unslider.com/unslider.min.js"></script>
<script>
$(function() {
$('.banner').unslider();
});
</script>
</head>
<body>
<br/>
<h1 style="font-family:verdana; font-size:50px; font-weigth:bold; font-style:italic;" align="center" > Logo </h1>
<div class="banner">
<ul>
<li>This is a slide.</li>
<li>This is another slide.</li>
<li>This is a final slide.</li>
</ul>
</div>
<div id = "footer">
<div class = "container">
<ul>
<li><a href = "?">Terms of use</a></li>
<li><a href = "?">Privacy</a></li>
<li><a href = "?">Cookies</a></li>
<li><a href = "?">Accessibility</a></li>
</ul>
</div>
</div>
</body>
</html>
CSS:
CSS:
.banner { position: relative; overflow: auto; }
.banner li { list-style: none; }
.banner ul li { float: left; }
Can someone check the link i provided above and tell me where i'm going wrong?
有人可以检查我上面提供的链接并告诉我哪里出错了吗?
Thanks
谢谢
Seems like none of the answers fix the problem at all, I guess i'll have to find a new slider.
似乎没有任何答案可以解决问题,我想我必须找到一个新的滑块。
Thanks for the help
谢谢您的帮助
回答by user2696254
Unslider picks the height from first list item (<li>
) from your list (<ul>
). Hence to make it work perfectly fine just add the height to first element.
Unslider<li>
从您的列表 ( <ul>
) 中选择第一个列表项 ( )的高度。因此,要使其完美运行,只需将高度添加到第一个元素即可。
回答by Denzelq
Check my unslider.com help file:
检查我的 unslider.com 帮助文件:
<!-- The HTML -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Unslider.com example</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" type="text/javascript"></script>
<script src="http://unslider.com/unslider.min.js"type="text/javascript"></script>
<!-- JavaScript -->
<script type="text/javascript">
$(function() {
$('.banner').unslider({
speed: 500, // The speed to animate each slide (in milliseconds)
delay: 3000, // The delay between slide animations (in milliseconds)
complete: function() {}, // A function that gets called after every slide animation
keys: true, // Enable keyboard (left, right) arrow shortcuts
dots: true, // Display dot navigation
fluid: false // Support responsive design. May break non-responsive designs
});
var unslider = $('.banner').unslider();
$('.prev').click(function() {
unslider.data('unslider').prev();
});
$('.next').click(function() {
unslider.data('unslider').next();
});
return false;
});
</script>
<!-- CSS -->
<style type="text/css">
* {
margin: 0;
padding: 0;
-webkit-box-sizing: border-box;
}
.banner {
position: relative;
width: 100%;
overflow: auto;
top: 50px;
/*z-index: -1;*/
font-size: 18px;
line-height: 24px;
text-align: center;
color: #FFFFFF;
text-shadow: 0 0 1px rgba(0,0,0,.05), 0 1px 2px rgba(0,0,0,.3);
background: #FFFFFF;
box-shadow: 0 1px 2px rgba(0,0,0,.25);
}
.banner ul {
list-style: none;
width: 300%;
}
.banner ul li {
display: block;
float: left;
min-height: 500px;
-o-background-size: 100% 100%;
-ms-background-size: 100% 100%;
-moz-background-size: 100% 100%;
-webkit-background-size: 100% 100%;
background-size: 100% 100%;
box-shadow: inset 0 -3px 6px rgba(0,0,0,.1);
}
.banner .inner {
padding: 360px 0 110px;
float: left;
vertical-align:-100px;
}
.banner h1, .banner h2 {
font-size: 40px;
line-height: 52px;
color: #fff;
}
.banner .btn {
display: inline-block;
margin: 25px 0 0;
padding: 9px 22px 7px;
clear: both;
color: #fff;
font-size: 12px;
font-weight: bold;
text-transform: uppercase;
text-decoration: none;
border : rgba(255, 255, 255, 0.4) solid 2px;
border-radius: 5px;
}
.banner .btn:hover {
background : rgba(255, 255, 255, 0.05);
}
.banner .btn:active {
-webkit-filter: drop-shadow(0 -1px 2px rgba(0,0,0,.5));
-moz-filter: drop-shadow(0 -1px 2px rgba(0,0,0,.5));
-ms-filter: drop-shadow(0 -1px 2px rgba(0,0,0,.5));
-o-filter: drop-shadow(0 -1px 2px rgba(0,0,0,.5));
filter: drop-shadow(0 -1px 2px rgba(0,0,0,.5));
}
.banner .btn, .banner .dot {
-webkit-filter: drop-shadow(0 1px 2px rgba(0,0,0,.3));
-moz-filter: drop-shadow(0 1px 2px rgba(0,0,0,.3));
-ms-filter: drop-shadow(0 1px 2px rgba(0,0,0,.3));
-o-filter: drop-shadow(0 1px 2px rgba(0,0,0,.3));
filter: drop-shadow(0 1px 2px rgba(0,0,0,.3));
}
.banner .dots {
position: absolute;
left: 0;
right: 0;
bottom: 20px;
width: 100%;
}
.banner .dots li {
display: inline-block;
width: 10px;
height: 10px;
line-height: 10px;
margin: 0 4px;
text-indent: -999em;
border: 2px solid #fff;
border-radius: 6px;
cursor: pointer;
opacity: .4;
-webkit-transition: background .5s, opacity .5s;
-moz-transition: background .5s, opacity .5s;
transition: background .5s, opacity .5s;
}
.banner .dots li.active {
background: #fff;
opacity: 1;
}
.unslider-arrow {
font-family: Expressway;
font-size: 50px;
text-decoration: none;
color: #3d3d3d;
background: rgba(255,255,255,0.7);
padding: 0 20px 5px 20px;
}
.next {
position: absolute;
top: 65%;
right: 0
}
.prev {
position: absolute;
top: 65%;
right: 90 /* change to left:0; if u wanna have arrow on left side */
}
</style>
</head>
<!-- Body of HTML document -->
<body>
<div class="slider">
<div class="banner">
<ul>
<li style="background-image: url('http://lorempixel.com/1200/600/');">
<div class="inner">
<h1>Some h1 text</h1>
<p>smaller p text</p>
<a class="btn" href="http://www.yourlink.com">Hyperlink</a>
</div>
</li>
<li style="background-image: url('http://lorempixel.com/1200/600/');">
<div class="inner">
<h1>Some h1 text</h1>
<p>smaller p text</p>
<a class="btn" href="http://www.yourlink.com">Hyperlink</a>
</div>
</li>
<li style="background-image: url('http://lorempixel.com/1200/600/');">
<div class="inner">
<h1>Some h1 text</h1>
<p>smaller p text</p>
<a class="btn" href="http://www.yourlink.com">Hyperlink</a>
</div>
</li>
<li style="background-image: url('http://lorempixel.com/1200/600/');">
<div class="inner">
<h1>Some h1 text</h1>
<p>smaller p text</p>
<a class="btn" href="http://www.yourlink.com">Hyperlink</a>
</div>
</li>
</ul>
</div>
<a href="#" class="unslider-arrow prev">←</a>
<a href="#" class="unslider-arrow next">→</a>
</div>
</body>
</html>
回答by Vedant Terkar
Hey The problem is with the height of the container.
嘿 问题在于容器的高度。
Because of the low height it isn't capable of displaying the overflow.
由于高度低,它无法显示溢出。
So i have made little changes to your code.
所以我对你的代码做了很少的改动。
And they are :
他们是:
<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Webpage</title>
<style type = "text/css">
.banner { position: relative; overflow: auto;
background: #0f0;
min-height: 100px; }
.banner li { list-style: none; }
.banner ul li { float: left; }
</style>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script src="http://unslider.com/unslider.min.js"></script>
<script>
$(document).ready(function(){
$(function() {
$('.banner').unslider();
});
});
</script>
</head>
<body>
<br/>
<h1 style="font-family:verdana; font-size:50px; font-weigth:bold; font-style:italic;" align="center" >Logo</h1>
<div class="banner">
<ul>
<li>This is a slide.</li>
<li>This is another slide.</li>
<li>This is a final slide.</li>
</ul>
</div>
<div id = "footer">
<div class = "container">
<ul>
<li><a href = "?">Terms of use</a></li>
<li><a href = "?">Privacy</a></li>
<li><a href = "?">Cookies</a></li>
<li><a href = "?">Accessibility</a></li>
</ul>
</div>
</div>
</body>
</html>
And It works for me !
它对我有用!
回答by mkutyba
Your code is good. Slider is created, but slides are outside the box and overflow is hidden so you don't see them. Add this css
你的代码很好。滑块已创建,但幻灯片在框外且溢出已隐藏,因此您看不到它们。添加这个css
.banner ul { margin: 0; padding: 0; }
回答by Zama Mohammed
You need to specify dots:true in your javascript code, for example, apply this, and you will see it works fine.
例如,您需要在 javascript 代码中指定 dots:true ,应用它,您会看到它工作正常。
Here is working jsfiddle link for you.
这是为您工作的 jsfiddle 链接。
$(function() {
$('.banner').unslider({
speed: 500, // The speed to animate each slide (in milliseconds)
delay: 3000, // The delay between slide animations (in milliseconds)
complete: function() {}, // A function that gets called after every slide animation
keys: true, // Enable keyboard (left, right) arrow shortcuts
dots: true, // Display dot navigation
fluid: false // Support responsive design. May break non-responsive designs
});
});