我有代码为展示工作,并隐藏div.当显示和隐藏活动时,我将如何添加两个不同的图标作为精灵图像?
例如:显示我的图标,然后是一个隐藏我的图标.
这是代码,我有:
http://jsfiddle.net/BLkpG/
- $(document).ready(function(){
- $(".slidingDiv").hide();
- $(".show_hide").show();
- $('.show_hide').click(function(){
- $(".slidingDiv").slideToggle();
- });
- });
切换到或 – 时,需要将图像更改为上述内容.
谢谢
解决方法
尝试这样的东西
jQuery的
- $(document).ready(function(){
- $(".slidingDiv").hide();
- $(".show_hide").show();
- $('.show_hide').toggle(function(){
- $("#plus").text("-");
- $(".slidingDiv").slideDown();
- },function(){
- $("#plus").text("+");
- $(".slidingDiv").slideUp();
- });
- });
HTML
- <a href="#" class="show_hide" id="plus">+</a>
- <div class="slidingDiv" style="display: block;">
- Check out the updated jQuery plugin for doing this: <a href="http://papermashup.com/jquery-show-hide-plugin/" class="show_hide" target="_blank" style="display: inline;">jQuery Show / Hide Plugin</a>
- </div>
CSS
- .show_hide {
- display:none;
- }
- .a{
- font: 2em Arial;
- text-decoration: none
- }
在这里查看本教程http://www.webstutorial.com/simple-jquery-toggle-tutorial-css-jquery-slide-toggle/jquery