前言 一个成熟的大型网站(如淘宝、京东等)的系统架构并不是开始设计就具备完整的高性能、高可用、安全等特性,它总是随着用户量的增加,业务功能的扩展 逐渐演变完善的,在这个过程中,开发模式、技术架构、设计思想也发生了很大的变化,就连技术人员也从几个人发展到一个部门甚至一条产品线。所以成熟的系统 架构是随业务扩展而完善出来的,并不是一蹴而就;不同业务特征的系统,会有各自的侧重点,例如淘宝,要解决海量的商品信息的搜索、下单、支付,例如腾讯, 要解决数亿的用户实时消息传输,百度它要处理海量的搜索请求,他们都有各自的业务特性,系统架构也有所不同。尽管如此我们也可以从这些不同的网站背景下, 找出其中共用的技术,这些技术和手段可以广泛运行在大型网站系统的架构中,下面就通过介绍大型网站系统的演化过程,来认识这些技术和手段。 一、最开始的网站架构 最初的架构,应用程序、数据库、文件都部署在一台服务器上,如图:…
jquery 很赞的背景图片转换插件 Backstretch
Backstretch
Backstretch is a simple jQuery plugin that allows you to add a dynamically-resized, slideshow-capable background image to any page or element. The image will stretch to fit the page/element, and will automatically resize as the window/element size changes.
Demo
There are a couple of examples included with this package, or feel free to check it out live on the project page itself.
Setup
Include the jQuery library (version 1.7 or newer) and Backstretch plugin files in your webpage (preferably at the bottom of the page, before the closing BODY tag):
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> <script src="jquery.backstretch.min.js"></script> <script> // To attach Backstrech as the body's background $.backstretch("path/to/image.jpg"); // You may also attach Backstretch to a block-level element $(".foo").backstretch("path/to/image.jpg"); // Or, to start a slideshow, just pass in an array of images $(".foo").backstretch([ "path/to/image.jpg", "path/to/image2.jpg", "path/to/image3.jpg" ], {duration: 4000}); </script>
Options
Name | Description | Type | Default |
---|---|---|---|
centeredX |
The ratio of the width/height of the image doesn’t always jive with the width/height of the window. This parameter controls whether or not we center the image on the X axis to account for the discrepancy. | Boolean | true |
centeredY |
This parameter controls whether or not we center the image on the Y axis to account for the aforementioned discrepancy. | Boolean | true |
fade |
This is the speed at which the image will fade in. Integers in milliseconds are accepted, as well as standard jQuery speed strings (slow, normal, fast). | Integer or String | 0 |
duration |
The amount of time in between slides, when using Backstretch as a slideshow, expressed as the number of milliseconds. | Integer | 5000 |
Slideshow API
Once you’ve instantiated a Backstretch slideshow, there are many actions that you can perform it:
// Start a slideshow $('.foo').backstretch([ 'path/to/image.jpg', 'path/to/image2.jpg', 'path/to/image3.jpg' ]); // Pause the slideshow $('.foo').backstretch("pause"); // Advance to the next slide $('.foo').backstretch("next");
Method | Description |
---|---|
.backstretch("show", n) |
Jump to the slide at a given index, where n is the number of the image that you’d like to display. Slide number starts at 0. |
.backstretch("prev") |
Display the previous image in a slideshow. |
.backstretch("next") |
Advance to the next image in a slideshow. |
.backstretch("pause") |
Pause the slideshow. |
.backstretch("resume") |
Resume a paused slideshow. |
.backstretch("destroy", preserveBackground) |
Destroy the Backstretch instance. Optionally, you can pass in a Boolean parameter, preserveBackground, to determine whether or not you’d like to keep the current image stretched as the background image. |
.backstretch("resize") |
This method is called automatically when the container (window or block-level element) is resized, however you can always call this manually if needed. |
Public Variables
Sometimes, you’ll want to access Backstretch’s images after you’ve instantiated the plugin. For example, perhaps you’d like to be able add more images to a slideshow. Doing so is easy. You can access the images array as follows:
$('.foo').backstretch([ 'path/to/image.jpg', 'path/to/image2.jpg', 'path/to/image3.jpg' ]); // Access the instance var instance = $('.foo').data('backstretch'); // Then, you can manipulate the images array directly instance.images.push('path/to/image4.jpg')
Additionally, the current index of a slideshow is available through the instance as well:
$("body").data("backstretch").index;
Events
backstretch.before
Backstretch will fire a “backstretch.before” event before a new image loads, triggering a function that is passed the event, Backstretch instance, and index of the image that will be displayed. If you listen for that event, you can, for example, coordinate other changes to coincide with your slideshow.
$(window).on("backstretch.before", function (e, instance, index) { // If we wanted to stop the slideshow after it reached the end if (index === instance.images.length - 1) { instance.pause(); }; });
backstretch.after
Backstretch will also fire a “backstretch.after” event after the new images has completed loading.
$(window).on("backstretch.after", function (e, instance, index) { // Do something });