This is my first jQuery plugin. I wrote several jQuery scripts but never made a real plugin just because I was I afraid of it's complexity. It turned out to be a lot easier than I thought so I went ahead and created this one.
Easy Slider (as I call this plugin) enables images or any content to slide horizontally or vertically on click. It is configurable with css alone. So, basically you link to plugin file, set the content up and style it with css.
Download easySlider.zip
Getting Started
First you'll need content and it should be wrapped inside a div containing an ordered list where each list item represents one slide. Here's a markup example:
<div id="slider">
<ul>
<li>content here...</li>
<li>content here...</li>
<li>content here...</li>
...
</ul>
</div>
You can basically put whatever you want inside list items as long as you keep the same dimensions. My initial idea was to use this slider for image gallery as on Templatica's homepage but I've used it for other stuff too.
To activate the script you will need to download the files, place jQuery file and easySlider.js somewhere on your site and link to them:
<script type="text/javascript" src="/js/jquery.js"></script>
<script type="text/javascript" src="/js/easySlider.js"></script>
The action starts when you add this lines of code to your JavaScript:
$(document).ready(function(){
$("#slider").easySlider();
});
This basically initiates the script on page load where "#slider" is css selector of the element(s) that you wish to apply script to. You can also use multiple elements using their class names i.e. $(".list").easySlider();
Next is up to your preferences - styling. This is how default styling looks like:
#slider ul, #slider li{
margin:0;
padding:0;
list-style:none;
}
#slider, #slider li{
width:500px;
height:200px;
overflow:hidden;
}
span#prevBtn{}
span#nextBtn{}
Not much there, is it? The most important thing here is to keep the same dimensions for the content area and each list item (slide). Also, overflow:hidden is obligatory. Other than that, you have free hands in adding your own style to the Easy Slider! To get an idea how it can be spiced up, you may take a look at Templatica's homepage.
How does it all work
Script automatically adds "previous" and "next" buttons in form of span elements with nested anchors just after the content element. Spans have assigned IDs that you can use for css selecting:
<span id="prevId"><a href="javascript:void(0);">Previous</a></span>
<span id="nextBtn"><a href="javascript:void(0);">Next</a></span>
On each click (previous or next button) script calculates the current "position" and makes a one step in requested direction. So, the slider jumps from one slide to another. Once it reaches the end (last slide), the "next" button fades away and re-appears only if "previous" button is clicked again. Same goes for sliding towards the beginning.
Options
The following options are configurable:
- prevId - id for "previous" button
- prevText - text for "previous" button
- nextId - id for "previous" button
- nextText - text for "next" button
- orientation - horizontal or vertical, horizontal is default and if you want vertical set this to 'vertical'
- speed - animation speed in milliseconds, default value is 800
Yes, you saw it correctly, vertical sliding is also possible! :)
Options are added when calling the script:
$(document).ready(function(){
$("#slider").easySlider({
prevText: 'Previous Slide',
nextText: 'Next Slide',
orientation: 'vertical'
});
});
Make sure that you don't put the comma after last option.
Demos
Here are some blank, non styled demos. Check out the script in action:
To check out styled demo, please visit Templatica.
What makes this slider script different
Because of it's simplicity and light-weightness (is that a word ?! ) I believe that is is much easier to deal with this plug in and configure it. The appearance is totally editable with css so all of you afraid of getting their hands dirty with JS code can easily use this.
from http://cssglobe.com/post/3783/jquery-plugin-easy-image-or-content-slider
分享到:
相关推荐
jQuery Slider Gallery - **简介**:支持滑动切换的图片画廊插件。 - **特点**: - 支持触摸操作。 - 可以自定义滑块样式。 ##### 9. jQuery Cycle Plugin - **简介**:功能全面的图片轮播插件。 - **特点**: ...
EasySlider 可能是一个用于创建幻灯片效果的轻量级 jQuery 插件。它可能支持基本的过渡效果和自定义选项。 **3.33 imgPreview** imgPreview 插件可能用于创建图像预览功能。它可能支持用户上传图片,并立即显示...
幻灯片效果是常用的内容展示方式之一,这是一种在有限的网页空间内展示系列项目时非常好的方法。今天要给大家分享的是10篇非常棒的 jQuery 幻灯片教程及16个优秀的 jQuery 幻灯片应用案例。...Easy Slider 1
5. **Easy Slider**:Easy Slider是一个功能丰富的jQuery滑动门插件,支持横向和纵向滑动,可自动滚动,具有多种控制选项,如“上一屏”、“下一屏”等,而且可以轻松定制样式和速度。 6. **ListNav**:ListNav是...
1. **Galleriffic**:这款插件利用jQuery Cycle plugin来创建图片展示,提供了缩略图、标题和描述等功能,非常适合创建高质量的在线相册或画廊。用户可以通过鼠标悬停或点击缩略图来浏览详细信息。 2. **ZoomImage*...
13. **Coda-Slider 2.0**:Coda Slider是一种流行的jQuery插件,用于创建水平滚动的内容滑块,可以用于导航或展示多个页面内容。 14. **jQuery Horizontal Tooltips menu**:这个教程教你如何创建水平工具提示菜单...