首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >jquery tabslideout插件,并希望检测div何时滑入滑出

jquery tabslideout插件,并希望检测div何时滑入滑出
EN

Stack Overflow用户
提问于 2012-12-20 22:53:06
回答 1查看 4.9K关注 0票数 4

我正在使用jquery tabslideout插件。它看起来很好,但我想检测一下tabslideout插件什么时候滑入滑出。如果我可以检测到,那么我就可以调用另一个例程。我还不知道如何在tabslideout div滑入和滑出时进行捕获。所以请给我指引。谢谢

以下是我的代码

代码语言:javascript
复制
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js" type="text/javascript"></script>
<script src="http://tab-slide-out.googlecode.com/files/jquery.tabSlideOut.v1.3.js"></script>

<script type="text/javascript">
$(function(){
$('.slide-out-div').tabSlideOut({
    tabHandle: '.handle',                     //class of the element that will become your tab
    pathToTabImage: 'images/contact_tab.gif', //path to the image for the tab //Optionally can be set using css
    imageHeight: '122px',                     //height of tab image           //Optionally can be set using css
    imageWidth: '40px',                       //width of tab image            //Optionally can be set using css
    tabLocation: 'left',                      //side of screen where tab lives, top, right, bottom, or left
    speed: 300,                               //speed of animation
    action: 'click',                          //options: 'click' or 'hover', action to trigger animation
    topPos: '200px',                          //position from the top/ use if tabLocation is left or right
    leftPos: '20px',                          //position from left/ use if tabLocation is bottom or top
    fixedPosition: false                      //options: true makes it stick(fixed position) on scroll
});

});

</script>

<style type="text/css">
.slide-out-div {
  padding: 20px;
  width: 250px;
  background: #ccc;
  border: 1px solid #29216d;
 }      
 </style>

 <div class="slide-out-div">
    <a class="handle" href="http://link-for-non-js-users.html">Content</a>
    <h3>Contact me</h3>
    <p>Thanks for checking out my jQuery plugin, I hope you find this useful.
    </p>
    <p>This can be a form to submit feedback, or contact info</p>
 </div>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-12-20 23:58:17

插件没有办法通知你它已经发生了,但是我已经修改了插件以允许你这样做。

我对插件的更改是添加一个回调函数(您可以在选项中提供一个),以便在动画完成后运行。

这是一个example

唯一的变化是提供了一个函数,当它滑入或滑出时可以调用它。就像这样

代码语言:javascript
复制
$(function(){
        $('.slide-out-div').tabSlideOut({
            tabHandle: '.handle',                     //class of the element that will become your tab
            pathToTabImage: 'http://wpaoli.building58.com/wp-content/uploads/2009/09/contact_tab.gif', //path to the image for the tab //Optionally can be set using css
            imageHeight: '122px',                     //height of tab image           //Optionally can be set using css
            imageWidth: '40px',                       //width of tab image            //Optionally can be set using css
            tabLocation: 'left',                      //side of screen where tab lives, top, right, bottom, or left
            speed: 300,                               //speed of animation
            action: 'click',                          //options: 'click' or 'hover', action to trigger animation
            topPos: '200px',                          //position from the top/ use if tabLocation is left or right
            leftPos: '20px',                          //position from left/ use if tabLocation is bottom or top
            fixedPosition: false,                      //options: true makes it stick(fixed position) on scroll
            onSlideOut: function() {
                alert('Opened');
            },
            onSlideIn: function() {
                alert('Closed');
            }
        });

    });

请注意,您需要使用我在JsFiddle上修改的版本。

希望这能有所帮助

更新

Op请求关于我对插件的更改的进一步信息。

首先,我添加了两个新属性到默认设置,这两个属性是空函数。

代码语言:javascript
复制
onSlideOut: function() {},
onSlideIn:  function() {} 

然后,我将该值放入代码中的animate方法的回调中。

代码语言:javascript
复制
//Square Bracket for emphasis only
obj.animate({top:'-' + properties.containerHeight}, settings.speed,[settings.onSlideIn]).removeClass('open'); 
obj.animate({top:'-3px'},  settings.speed,[settings.onSlideOut]).addClass('open');

然后,用户能够提供他们自己的方法实现,以覆盖默认方法。

如果你需要更多的钩子来处理代码,那么你可以考虑触发和监听自定义事件,而不是使用回调。

票数 8
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13974780

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档