整合营销服务商

电脑端+手机端+微信端=数据同步管理

免费咨询热线:

手把手教你用jQuery Mobile做相册

手把手教你用jQuery Mobile做相册

一、项目背景】

jQuery是当前很流行的一个JavaScript框架,使用类似于CSS的选择器,可以方便的操作HTML元素,拥有很好的可扩展性,拥有不少jQuery插件,也可对个方面进行插件开发。jQuery可以快速找到文档中的html元素,并对其进行操作,如隐藏、显示、改变样式......


【二、项目准备】

1. 下载 jQuery Mobile

如果你想将 jQuery Mobile 放于你的主机中,你可以从下面这个网站下载该文件。

jQuerymobile.com


2. 在你的网页中添加 jQuery Mobile

你可以通过以下几种方式将jQuery Mobile添加到你的网页中:

  • 从 CDN 中加载 jQuery Mobile (推荐)。
  • 从jQuerymobile.com 下载 jQuery Mobile库。

3. 从 CDN 中加载 jQuery Mobile

<!-- meta使用viewport以确保页面可自由缩放 -->
<meta name="viewport" content="width=device-width, initial-scale=1">

<!-- 引入 jQuery Mobile 样式 -->
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">

<!-- 引入 jQuery 库 -->
<script src="http://code.jquery.com/jquery-1.12.2.min.js"></script>

<!-- 引入 jQuery Mobile 库 -->
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>

</head>


【三、项目实施】

1. body里面写入以下代码,(img标签的src属性导入自己喜欢的图片,设置图片的样式)。

<div data-role="page">
    <a href="#popup_1" data-rel="popup" data-position-to="window">
        <img src="images/p1.jpg" style="width:49%">
    </a>
    <a href="#popup_2" data-rel="popup" data-position-to="window">
        <img src="images/p2.jpg" style="width:49%">
    </a>
    <a href="#popup_3" data-rel="popup" data-position-to="window">
        <img src="images/p3.jpg" style="width:49%">
    </a>
    <a href="#popup_4" data-rel="popup" data-position-to="window">
        <img src="images/p4.jpg" style="width:49%">
    </a>
    <a href="#popup_5" data-rel="popup" data-position-to="window">
        <img src="images/p5.jpg" style="width:49%">
    </a>
    <a href="#popup_6" data-rel="popup" data-position-to="window">
        <img src="images/p6.jpg" style="width:49%">
    </a>


2. 给图片添图标。

<div data-role="popup" id="popup_2">
       <a href="#" data-rel="back" data-role="button" data-icon="delete" data-iconpos="notext" class="ui-btn-right">Close</a>
       <img src="images/p2.jpg" style="max-height:512px;" alt="pic2">
    </div>
    <div data-role="popup" id="popup_3">
        <a href="#" data-rel="back" data-role="button" data-icon="delete" data-iconpos="notext" class="ui-btn-right">Close</a>
        <img src="images/p3.jpg" style="max-height:512px;" alt="pic3">
    </div>
<div data-role="popup" id="popup_4">
        <a href="#" data-rel="back" data-role="button" data-icon="delete" data-iconpos="notext" class="ui-btn-right">Close</a>
        <img src="images/p4.jpg" style="max-height:512px;" alt="pic4">
    </div>
<div data-role="popup" id="popup_5">
        <a href="#" data-rel="back" data-role="button" data-icon="delete" data-iconpos="notext" class="ui-btn-right">Close</a>
        <img src="images/p5.jpg" style="max-height:512px;" alt="pic5">
    </div>


提示:jQuery Mobile 中的按钮会自动获得样式,这增强了他们在移动设备上的交互性和可用性。我们推荐您使用 data-role="button" 的 <a> 元素来创建页面之间的链接,而 <input> 或 <button> 元素用于表单提交。


【四、效果展示】

1. 下载一个叫Opera Mobile的软件。

Opera Mobile emulator是一款APP模拟器,专门用来测试APP项目。不过这个需要进行安装,这个模拟器可以根据手机屏幕大小进行模拟测试。

2. 百度搜索opera mobile,选择第一个网址。

3. 安装教程可以直接百度,这里不再赘述。

4. 安装完成后把我们的页面拖进去就可以了。(下面是界面效果图)


5. 效果图如下图所示。


6. 点击其中一张图片,会放大显示,效果图如下图所示。

【五、总结】

1. 本文章就jQuery Mobile在应用中出现的难点和重点,做出了相对于的解决方案。

2. 使更多的人去了解jQuery Mobile。

3. 欢迎大家积极尝试,有时候看到别人实现起来很简单,但是到自己动手实现的时候,总会有各种各样的问题,切勿眼高手低,勤动手,才可以理解的更加深刻。

4. 如果需要本文源码,请在公众号后台回复“设计相册”四个字获取。


看完本文有收获?请转发分享给更多的人

IT共享之家

想学习更多Python网络爬虫与数据挖掘知识,可前往专业网站:http://pdcfighting.com/

天学习了平面动画,今天来3D动画:

css3的强大之处就在于它可以用很少量的标签,来实现一些要用到插件或者js,jq很多代码才能实现的复杂功能。随着css3版本的推进,各浏览器的兼容性也会越来越好,开发会很容易。

实现上图的关键点在于,如何布局不了解css3的可能会说要定位,其实不然,我们只需要transform的rotate和translate即可轻松实现旋转位移.至于图片了可以用img也可以直接背景图。下面是我的页面结构和css样式

<style>

*{margin:0; padding:0; list-style: none;}

div{

width: 105px;

height: 150px;

margin:100px auto;

-webkit-perspective: 1000;

-webkit-perspective-origin: center center;

}

ul{

width: 105px;

height: 150px;

position: relative;

-webkit-transform-style: preserve-3d;

-webkit-transform:rotateX(-16deg) rotateY(0deg) rotateZ(0deg);

-webkit-animation: ;

}

@-webkit-keyframes run{

from{ }

to{ }

}

ul li{width: 105px; height: 150px; position: absolute; -webkit-background-size:100% 100%;}

ul li:nth-child(1){

background-image: url(images/01.jpg);

-webkit-transform: translateZ(200px);

}

ul li:nth-child(2){

background-image: url(images/02.jpg);

-webkit-transform:rotateY(30deg) translateZ(200px);

}

ul li:nth-child(3){

background-image: url(images/03.jpg);

-webkit-transform:rotateY(60deg) translateZ(200px);

}

ul li:nth-child(4){

background-image: url(images/04.jpg);

-webkit-transform:rotateY(90deg) translateZ(200px);

}

ul li:nth-child(5){

background-image: url(images/05.jpg);

-webkit-transform:rotateY(120deg) translateZ(200px);

}

ul li:nth-child(6){

background-image: url(images/06.jpg);

-webkit-transform:rotateY(150deg) translateZ(200px);

}

ul li:nth-child(7){

background-image: url(images/07.jpg);

-webkit-transform:rotateY(180deg) translateZ(200px);

}

ul li:nth-child(8){

background-image: url(images/08.jpg);

-webkit-transform:rotateY(210deg) translateZ(200px);

}

ul li:nth-child(9){

background-image: url(images/09.jpg);

-webkit-transform:rotateY(240deg) translateZ(200px);

}

ul li:nth-child(10){

background-image: url(images/10.jpg);

-webkit-transform:rotateY(270deg) translateZ(200px);

}

ul li:nth-child(11){

background-image: url(images/11.jpg);

-webkit-transform:rotateY(300deg) translateZ(200px);

}

ul li:nth-child(12){

background-image: url(images/12.jpg);

-webkit-transform:rotateY(330deg) translateZ(200px);

}

</style>

结构是div抱着ul和li有多少图片就有多少个li(这里就不展示了)

只有这个相册就可以旋转了么,当然不会,各位还需要在上文@-webkit-keyframes处补全animation动画即可,animation动画在上篇《纯css实现无缝滚动》中又详细代码 拿过来即可

注本头条号,专注做前端

今天要分享的是一款特别的 html5/css3 焦点图效果,不依赖jquery,全程JS 手写,代码量不大,百行左右,它的特别之处在于 可以多维度的切换

谁说程序员没有情调? 拿这个去给女票定制个专属相册吧

//