我想在不使用任何滑块插件的情况下创建自己的幻灯片。 这是我的代码:
- 在页脚---
<script type="text/javascript" src="<?php bloginfo( 'template_url' );?>/js/jquery.cycle.all.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script>
$('#slideshow').cycle({
fx: 'scrollLeft',
timeout: 3000,
pager: '#navSlider',
slideExpr: '#mySlide'
});
</script>
- 在我的front-page.php中 -
<div class="slideContent">
<div id="navSlider"></div>
<div id="slideshow" class="pics" style="position: relative; overflow: hidden;">
<div id="mySlide">
<div id="textBack"></div>
<div id="textSlide">the title 1</div>
<img src="<?php bloginfo( 'template_url' );?>/slideimage/myimage1.jpg">
</div>
<div id="mySlide">
<div id="textBack"></div>
<div id="textSlide">the title 2</div>
<img src="<?php bloginfo( 'template_url' );?>/slideimage/myimage2.jpg">
</div>
</div>
</div>
- 在css文件中----
#slideshow {
width: 232px;
height: 232px;
}
#navSlider {
z-index: 50;
position:absolute;
width:19px;
top:0;
right:-5px;
}
#navSlider a {
display:block;
height:31px;
margin: 0 0px;
padding: 3px 6px;
border: 1px solid #ccc;
background: #cff;
text-decoration: none
}
#navSlider a.activeSlide {
background: #aaf;
padding:9px 0 0 0;
text-align:center;
}
#navSlider a:focus {
outline: none;
}
#textBack {
background-color:#000;
/*color:#FFF;*/
opacity: 0.4;
height:30px;
position:absolute;
right:0;
bottom:0;
width:232px;
/*text-align:center;*/
}
#textSlide {
color:#fff;
height:26px;
position:absolute;
bottom:0;
right:10px;
font-size:18px;
/* margin:auto;*/
/* width:232px;*/
/* text-align:center;*/
}
.pics {
height: 232px;
width: 232px;
padding: 0;
margin: 0;
}
.pics img {
padding: 15px;
border: 1px solid #ccc;
background-color: #eee;
width: 200px;
height: 200px;
top: 0;
left: 0
}
.slideContent {
margin: 30px auto;
width: 244px;
height: 234px;
position:relative;
top: 0;
left: 0;
background-color:#069;
}
这实际上非常适用于非wordpress环境。我不知道为什么它不会在wordpress中工作。是否有另一个滑块是否重要?
答案 0 :(得分:2)
我发现它.....它只是没有注册的js文件.....我用这个
wp_enqueue_script( 'jquery' );
在functions.php文件中:
wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'cycle', 'http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js' );
wp_enqueue_script( 'theme-script', get_template_directory_uri() . '/js/jquery.cycle.all.js', 'jquery' );