jquery页面转换插件smoothstate.js

所属分类:UI-加载

 45612  326  查看评论 (1)
分享到微信朋友圈
X
jquery页面转换插件smoothstate.js ie兼容10

使用

smoothState.js是允许你实现真正简洁的站点页面转换。为了实现这样站点效果,我们需要通过smoothState处理处理一些问题:

    -更新你的用户与popState的URL

    -从您的服务器通过AJAX获取内容

    -页面上的内容替换为新的内容


最基本方法

为了实现这一系统的功能,您可以运行:

$('#body').smoothState();

这行代码将导致我们的网页链接的任何内部#body容器的内容无需重新加载页面。


添加页面转换

在传统动画,场景的变化需要抽出一组帧,得到连续快速地交换出去。同样,smoothState允许您定义一个数组的函数,返回页面被换出的标记。这很有用,因为它允许您添加所需的HTML框架实现CSS动画。这里有一个基本的例子,一个简单的褪色效果:

Javascript:

$('#body').smoothState({
  renderFrame: [
    // Frame 1: sets up scaffolding needed for CSS animations
    function ($content, $container) {
      var currentHTML = $container.html(),
          newHTML     = $('<div/>').append($content).html(),
          html        = [
            '<div class=\'content\' style=\'height:' + $container.height() +  'px;\'>',
            '<div class=\'page page--old\'>' + currentHTML + '</div>',
            '<div class=\'page page--new\'>' + newHTML + '</div>',
            '</div>'
          ].join('');
      return html;
    },
    // Frame 2: cleans up extra markup added for CSS animations
    function ($content) {
      return $('<div/>').append($content).html();
    }
  ]
});


CSS:

/* Page transitions - simple fade effect
------------------------------------------------- */
#body .content {
  position: relative;
  z-index: 1;
}
#body .page {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
}
#body .page--old {
  animation: fadeOut 0.1s ease; /* Don't forget to add vendor prefixes! */
  opacity: 0;
  z-index: 1;
}
#body .page--new {
  visibility: visible;
  animation: fadeIn 0.4s ease;
  z-index: 2;
}
/* Animations classes
------------------------------------------------- */
@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
@keyframes fadeOut {
  from {
    opacity: 1;
  }
  to {
    opacity: 2;
  }
}

你可以看到这个简单的演示,会影响自己的网站

相关插件-加载

jquery图片延迟加载

不有添加多余的属性值,直接设src属性值就ok。
  加载
 41270  391

11种Loading 动态效果+随机样式

css实现动态loading 效果
  加载
 69279  506

jquery实现图片预加载

jquery实现图片预加载
  加载
 49143  446

HTML5手机端手指滑动上拉加载

jQuery HTML5手机端手指滑动上拉加载代码是一款通过jquery实现tab切换和上拉加载更多的效果,适用于手机端页面开发。
  加载
 54291  582

讨论这个项目(1)回答他人问题或分享插件使用方法奖励jQ币 评论用户自律公约

    ё呻谨孑? 0
    2016/6/1 17:06:49
    怎么实现左右切换 回复
😃
  • 😀
  • 😉
  • 😥
  • 😵
  • 😫
  • 😘
  • 😡
  • 👍
  • 🌹
  • 👏
  • 🍺
  • 🍉
  • 🌙
  • 💖
  • 💔
😃
  • 😀
  • 😉
  • 😥
  • 😵
  • 😫
  • 😘
  • 😡
  • 👍
  • 🌹
  • 👏
  • 🍺
  • 🍉
  • 🌙
  • 💖
  • 💔
取消回复