Hiển thị các bài đăng có nhãn Góc Lập Trình. Hiển thị tất cả bài đăng
Hiển thị các bài đăng có nhãn Góc Lập Trình. Hiển thị tất cả bài đăng

22 thg 2, 2011

[Java Script] Insert text vào textarea và giữ nguyên vị trí con trỏ

0 nhận xét
Thất Tình.Biz | Phần mềm | Tin tức | Thủ Thuật | Phim | Game|Teen Sock| Scandan



Đoạn code này dùng để chèn 1 đoạn text vào ô textare mà vẫn giữ được vị trí hiện tại của con trỏ trên textarea.

<script>
function BASIC_InsertTag(tagOpen, tagClose, sampleText) {
var clientPC = navigator.userAgent.toLowerCase(); // Get client info
var is_gecko = ((clientPC.indexOf('gecko')!=-1) && (clientPC.indexOf('spoofer')==-1)
&& (clientPC.indexOf('khtml') == -1) && (clientPC.indexOf('netscape/7.0')==-1));
var areas = document.getElementsByTagName('textarea');
var txtarea = areas[0];
if (document.selection  && !is_gecko) {
var theSelection = document.selection.createRange().text;
if (!theSelection) {
theSelection=sampleText;
}
txtarea.focus();
if (theSelection.charAt(theSelection.length - 1) == " ") { // exclude ending space char, if any
theSelection = theSelection.substring(0, theSelection.length - 1);
document.selection.createRange().text = tagOpen + theSelection + tagClose + " ";
} else {
document.selection.createRange().text = tagOpen + theSelection + tagClose;
}
// Mozilla
} else if(txtarea.selectionStart || txtarea.selectionStart == '0') {
var replaced = false;
var startPos = txtarea.selectionStart;
var endPos = txtarea.selectionEnd;
if (endPos-startPos) {
replaced = true;
}
var scrollTop = txtarea.scrollTop;
var myText = (txtarea.value).substring(startPos, endPos);
if (!myText) {
myText=sampleText;
}
var subst;
if (myText.charAt(myText.length - 1) == " ") { // exclude ending space char, if any
subst = tagOpen + myText.substring(0, (myText.length - 1)) + tagClose + " ";
} else {
subst = tagOpen + myText + tagClose;
}
txtarea.value = txtarea.value.substring(0, startPos) + subst +
txtarea.value.substring(endPos, txtarea.value.length);
txtarea.focus();
if (replaced) {
var cPos = startPos+(tagOpen.length+myText.length+tagClose.length);
txtarea.selectionStart = cPos;
txtarea.selectionEnd = cPos;
} else {
txtarea.selectionStart = startPos+tagOpen.length;
txtarea.selectionEnd = startPos+tagOpen.length+myText.length;
}
txtarea.scrollTop = scrollTop;
}
if (txtarea.createTextRange) {
txtarea.caretPos = document.selection.createRange().duplicate();
}
}</script>
<form id="form1" name="form1" method="post" action="">
<textarea name="textfield" id="textfield"></textarea>
<a href="javascript:BASIC_InsertTag('', '', 'In đậm');">Insert B</a>
</form>

 

[Java Script] Tự hover cho 1 tag HTML bằng JavaScript

0 nhận xét
Thất Tình.Biz | Phần mềm | Tin tức | Thủ Thuật | Phim | Game|Teen Sock| Scandan

Hàm này sẽ tự động set css cho tag TAG là css_on khi mouseover và css_off khi mouseout
<style>
.mouseover { background: red; }
.mouseout { background: blue; }
</style>
<script>
function BASIC_HOVER(tag,css_on,css_off){
var obj = document.getElementsByTagName(tag);
for(i=0;i<obj.length;i++){
if(obj[i].className == css_off){
obj[i].onmouseover = function() {
this.className = css_on;
}
obj[i].onmouseout = function() {
this.className = css_off;
}
}
}
}
</script>
<body onload="BASIC_HOVER('div','mouseover','mouseout')">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
</body>
 

[Java Script] Tạo vùng quảng cáo trổi nổi trên trang web.

0 nhận xét
Thất Tình.Biz | Phần mềm | Tin tức | Thủ Thuật | Phim | Game|Teen Sock| Scandan


Các bạn chắc đã quen thuộc với việc 1 trang web có 2 vùng quảng cáo chạy dọc biên. Hiện tại trên mạng có khá nhiều code giải quyết bài toán này, nhưng thường khá là phức tạp, rườm rà. Mấy hôm trước có 1 người bạn nhờ mình viết, tiện thể post lên để anh em tham khảo và áp dụng.
Code của mình có thể còn dài dòng hơn, nhưng có ưu điểm là dùng rất dễ và có thể áp dụng cho rất nhiều trường hợp.
<?

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>uoon demo Set Position</title>
<style type="text/css">
.float {
width: 115px;
height: 200px;
border: solid 1px blue;
}
</style>
</head>
<body>
<div style="width: 2000px;height: 2000px;">
<div id="a" class="float">a</div>
<div id="b" class="float">b</div>
<div id="c" class="float">c</div>
</div>
</body>
<script type="text/javascript">
function setPosition(id, position) {
var store = {
ram : {
top : 0,
left : 0,
right : 0,
bottom : 0
},
rom : {
top : null,
left : null,
right : null,
bottom : null
}
};
for (var i in position) {store.rom[i] = position[i];}
var element = document.getElementById(id);
for (i in store) {element[i] = store[i];}
element.rom.move = function() {
if (window.innerHeight) {
var topPage = window.pageYOffset;
var leftPage = window.pageXOffset;
var rightPage = leftPage + window.innerWidth - element.offsetWidth;
var bottomPage = topPage + window.innerHeight - element.offsetHeight;
}
else {
var topPage = document.body.scrollTop;
var leftPage = document.body.scrollLeft;
var rightPage = leftPage + document.body.clientWidth - element.offsetWidth;
var bottomPage = topPage + document.body.clientHeight - element.offsetHeight;
}
element.style.position = "absolute";
if (element.rom.top != null) {
element.ram.top += Math.round((topPage + element.rom.top - element.ram.top)/20);
element.style.top = element.ram.top;
}
if (element.rom.left != null) {
element.ram.left += Math.round((leftPage + element.rom.left - element.ram.left)/20);
element.style.left = element.ram.left;
}
if (element.rom.right != null) {
element.ram.right += Math.round((rightPage - element.rom.right - element.ram.right)/20);
element.style.left = element.ram.right;
}
if (element.rom.bottom != null) {
element.ram.bottom += Math.round((bottomPage - element.rom.bottom - element.ram.bottom)/20);
element.style.top = element.ram.bottom;
}
setTimeout("document.getElementById('"+element.id+"').rom.move()",10);
};
element.rom.move();
}
setPosition("a", {top: 20, right: 30});
setPosition("b", {bottom: 20, right: 30});
setPosition("c", {top: 20, left: 30});
</script>
</body>
</html>
?>
Muốn đặt một vùng quảng  cáo ở vị trí nào bạn chỉ  cần gọi hàm setPosition và truyền vào cho nó id của vùng quảng cáo và vị trí mà bạn muốn nó xuất hiện như sau:
Vd:
setPosition("ad", {top: 20, left: 100});
hàm này chỉ hỗ trợ 4 loại định vị là top, left, right, bottom
khi sử dụng tùy ý thiết lập.
Code của mình có thể còn dài dòng hơn, nhưng có ưu điểm là dùng rất dễ và có thể áp dụng cho rất nhiều trường hợp.
<?
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>uoon demo Set Position</title>
<style type="text/css">
.float {
width: 115px;
height: 200px;
border: solid 1px blue;
}
</style>
</head>
<body>
<div style="width: 2000px;height: 2000px;">
<div id="a" class="float">a</div>
<div id="b" class="float">b</div>
<div id="c" class="float">c</div>
</div>
</body>
<script type="text/javascript">
function setPosition(id, position) {
var store = {
ram : {
top : 0,
left : 0,
right : 0,
bottom : 0
},
rom : {
top : null,
left : null,
right : null,
bottom : null
}
};
for (var i in position) {store.rom[i] = position[i];}
var element = document.getElementById(id);
for (i in store) {element[i] = store[i];}
element.rom.move = function() {
if (window.innerHeight) {
var topPage = window.pageYOffset;
var leftPage = window.pageXOffset;
var rightPage = leftPage + window.innerWidth - element.offsetWidth;
var bottomPage = topPage + window.innerHeight - element.offsetHeight;
}
else {
var topPage = document.body.scrollTop;
var leftPage = document.body.scrollLeft;
var rightPage = leftPage + document.body.clientWidth - element.offsetWidth;
var bottomPage = topPage + document.body.clientHeight - element.offsetHeight;
}
element.style.position = "absolute";
if (element.rom.top != null) {
element.ram.top += Math.round((topPage + element.rom.top - element.ram.top)/20);
element.style.top = element.ram.top;
}
if (element.rom.left != null) {
element.ram.left += Math.round((leftPage + element.rom.left - element.ram.left)/20);
element.style.left = element.ram.left;
}
if (element.rom.right != null) {
element.ram.right += Math.round((rightPage - element.rom.right - element.ram.right)/20);
element.style.left = element.ram.right;
}
if (element.rom.bottom != null) {
element.ram.bottom += Math.round((bottomPage - element.rom.bottom - element.ram.bottom)/20);
element.style.top = element.ram.bottom;
}
setTimeout("document.getElementById('"+element.id+"').rom.move()",10);
};
element.rom.move();
}
setPosition("a", {top: 20, right: 30});
setPosition("b", {bottom: 20, right: 30});
setPosition("c", {top: 20, left: 30});
</script>
</body>
</html>
?>
Muốn đặt một vùng quảng  cáo ở vị trí nào bạn chỉ  cần gọi hàm setPosition và truyền vào cho nó id của vùng quảng cáo và vị trí mà bạn muốn nó xuất hiện như sau:
Vd:
setPosition("ad", {top: 20, left: 100});
hàm này chỉ hỗ trợ 4 loại định vị là top, left, right, bottom
khi sử dụng tùy ý thiết lập.
 

[Java Script] 21 Brilliant jQuery Image Gallery/Slideshow Plugins

0 nhận xét
Thất Tình.Biz | Phần mềm | Tin tức | Thủ Thuật | Phim | Game|Teen Sock| Scandan

Image galleries and slideshows provide a good user experience and make viewing images more pleasant and intuitive on your website. With the advent of powerful JavaScript frameworks like jQuery, Prototype, Mootools etc., the quality of JavaScript based image galleries and slideshows have improved dramatically.
As these frameworks are getting popular day by day, more and more web developers are coming out with new and creative ideas every day. Here are 21 brilliant jQuery plugins which you can easily use to create an image gallery/slideshow for your website.

1. Spacegallery

Spacegallery displays your images with a nice 3D effect and it is also pretty easy to use and customize.

2. prettyPhoto

prettyPhoto might look like jQuery Lightbox clone but it supports videos, flash, YouTube videos, iFrames besides images. It also comes with useful API and 4 beautiful themes. It is a great plugin to create an image as well as multimedia gallery.

3. Zoomimage

Stylish way to present your images in a nice popup with a drop shadow and border.

4. Pirobox

Another lightbox based image gallery plugin that resizes images based on browser size and next/prev links can be placed inside or outside of the image.

5. slideViewerPro

slideViewerPro is a fully customizable jQuery image gallery engine that lets you create outstanding sliding image galleries for your projects or interactive galleries within blog posts.

6. Galleria

Galleria generates an image gallery from an unordered list and once the images are loaded, thumbnail navigation is generated. It is easy to customize using just CSS and degrades gracefully if JavaScript is disabled.

7. jQuery PanelGallery

jQuery PanelGallery generates a slideshow of images with a unique transition. Image transition occurs in a sequential manner displaying the new image panel by panel, thus the name PanelGallery. It is lightweight and allows you to change the direction of panel transition.

8. PikaChoose

Pikachoose allows easy presentation of a bunch of images using slideshows with nice thumbnails, next/prev buttons and autoplay options.

9. jQuery Gallery Plugin

This plugin will transform a list of images into a flash like image gallery. Thumbnail navigation only shows up when you hover over the image and behaves like infinite carousel.

10. EOGallery

EOGallery creates an animated slideshow and images are displayed in larger size using jQuery Thickbox plugin.

11. Smooth Div Scroll

As the name suggests, this plugin scrolls content smoothly and horizontally in either left or right direction. This plugin can scroll any html content and if you use images, you’ll end up with a nice smoothly scrolling slideshow.

12. Sliding Image Gallery

Sliding image gallery displays a number of images in an easy to use manner just like the iTunes Album Viewer. It is quite easy to implement and gives you a lot of options to customize.

13. Step Carousel Viewer

This plugin displays images or any HTML content by side scrolling them left or right with a smooth sliding animation during transition. And with its two public methods and two custom event handlers, you can customize it to your requirement easily.

14. jQuery Virtual Tour

With this plugin, you can convert panoramic views into virtual tours, it degrades gracefully if JavaScript is disabled.

15. Ultimate Fade In Slide Show

This is a robust, cross browser fade in slideshow script that incorporates some of your most requested features all rolled into one.

16. ThickBox Gallery

jQuery Thickbox plugin can be used for creating a nice image viewer that shows images in a lightbox and supports keyboard shortcuts to navigate through the images.

17. jQuery Lightbox

This one is a simple elegant and unobtrusive plugin to create an overlay image viewer that supports keyboard shortcuts and requires minimal coding effort.

18. GalleryView

GalleryView lets you create a flexible and attractive content that is very easy to implement and customize. Also, their way of explaining the anatomy of GalleryView plugin is very intuitive.

19. Flickr Gallery

Flickr Gallery generates a slideshow whose size varies with the size of image. As the name suggests, it can directly pull images from a flickr account(needs Flickr API key) or you can use just a simple unordered list. Thumbnail navigation is intuitive with a nice scrolling bar.

20.Easy Slider

Easy slider enables images to slide either horizontally or vertically and it can be styled easily using CSS. The latest version of this plugin supports continuous scroll instead of jumping over to first slide from last slide.

21. SuperSized

Using Supersized, you can display large sized photos easily as it will scale the images automatically depending on browser size and supports preloading of images for better experience.

 

[Java Script] Interactive Photo Desk with jQuery and CSS3

0 nhận xét

View demo

Download source
In this little experiment we created an interactive photo desk that provides some “realistic” interaction possibilities for the user. The idea is to have some photos on a surface that can be dragged and dropped, stacked and deleted, each action resembling the real world act.
For example, if we drag a picture, it get’s “picked up” first, making it appear a little bit bigger, since it would be closer to us. Dropping it results in the picture being “thrown back” to the table, in a random rotation. Viewing all photos mirrors the action of collecting all images into a pile and viewing the first one in a none rotated way. Clicking to see the next one then, makes the previous one being thrown back to the surface. Deleting an image will make it appear as a crumpled paper ball.
When using the shuffle function, the photos get rotated and spread over the desk randomly.
You can download the source code of this and experiment with it, there are many more possibilities to discover and integrate.
We are using two important jQuery plugins: 2D Transform for animating rotations and Shadow Animation for animating the box shadow.
The images are taken from the amazing photostream of tibchris on Flickr.
The rotation did not work well with IE (although in principle it should) so we don’t rotate when IE is used.
We hope you enjoy this little experiment!!
View demo

Download source

[Java Script] Jquery Image Highlighting and Preview

0 nhận xét
Thất Tình.Biz | Phần mềm | Tin tức | Thủ Thuật | Phim | Game|Teen Sock| Scandan


View demo

Download source
In this tutorial we will show you how to highlight and preview images that are integrated in an article or spread over a page. This is a nice way to allow users to view a bigger version of an image that is relevant to some context. We will highlight images on a delayed hover and offer a preview mode which will enlarge and center the bigger version of the image on the screen.
Let’s start!

The Markup

For the HTML structure we simply need to consider the image and its class. The image can be placed anywhere in your website:
<img src="images/thumbs/1.jpg" alt="images/1.jpg"/>
We use the alt attribute to add the reference to the bigger image.
We will also add an overlay element before the body ends:
<div id="ih_overlay" style="display:none;"></div>
The structure that we will be creating with the JavaScript will look as follows:
<div id="ih_clone">
 <span></span>
 <img src="images/1.jpg">
</div>
This structure will not be placed in our HTML – it will be created dynamically.
Now, let’s take a look at the style.

The CSS

First, we will define the style for the overlay:
.ih_overlay{
 position:fixed;
 top:0px;
 left:0px;
 right:0px;
 bottom:0px;
 background:#000;
 z-index:10;
 opacity:0.9;
 filter:progid:DXImageTransform.Microsoft.Alpha(opacity=90);
}
The filter property is used for applying transparency in IE. We make the overlay fixed in order to always be shown, even if we scroll the page.
The image that we want to apply our effect to will have the following style:
img.ih_image{
 margin:10px 0px;
 position:relative;
 -moz-box-shadow:1px 1px 4px #000;
 -webkit-box-shadow:1px 1px 4px #000;
 box-shadow:1px 1px 4px #000;
 opacity:0.7;
 filter:progid:DXImageTransform.Microsoft.Alpha(opacity=70);
}
It’s pretty plain, we just add some box shadow to it.
In our JavaScript we will create a wrapper that contains a clone of the image that we are hovering. It will get the same positions as the current image. That’s why we do not define the top and left here, but dynamically in the JS.
.ih_image_clone_wrap{
 position:absolute;
 z-index:11;
}
We will also add some spans with icons that will either show a magnifying glass, a loading image or a cross. We define all common properties as follows:
.ih_image_clone_wrap span.ih_zoom,
.ih_image_clone_wrap span.ih_loading,
.ih_image_clone_wrap span.ih_close{
 position:absolute;
 top:10px;
 right:10px;
 width:24px;
 height:24px;
 -moz-border-radius:6px;
 -webkit-border-radius:6px;
 border-radius:6px;
 opacity:0.8;
 cursor:pointer;
 -moz-box-shadow:1px 1px 2px #000;
 -webkit-box-shadow:1px 1px 2px #000;
 box-shadow:1px 1px 2px #000;
 z-index:999;
 filter:progid:DXImageTransform.Microsoft.Alpha(opacity=80);
}
The specific properties for each class, like the background, will be defined as follows:
.ih_image_clone_wrap span.ih_zoom{
 background:#000 url(../icons/zoom.png) no-repeat center center;
}
.ih_image_clone_wrap span.ih_loading{
 background:#000 url(../icons/loader.gif) no-repeat center center;
}
.ih_image_clone_wrap span.ih_close{
 background:#000 url(../icons/close.png) no-repeat center center;
}
.ih_image_clone_wrap img{
 opacity:0.7;
 -moz-box-shadow:1px 1px 10px #000;
 -webkit-box-shadow:1px 1px 10px #000;
 box-shadow:1px 1px 10px #000;
 filter:progid:DXImageTransform.Microsoft.Alpha(opacity=70);
}
The full sized image that we will load on top of the thumbnail, will have the following style:
.ih_image_clone_wrap img.preview{
 opacity:1;
 position:absolute;
 top:0px;
 left:0px;
}
And now, let’s add some magic!

The JavaScript

In our jQuery function we will start by defining a variable to control the timing of the highlight effect.
When we hover over an image with the specific class we create our div with the class ih_image_clone_wrap and define its position by getting the position of the current image.
/**
* timeout to control the display of the overlay/highlight
*/
var highlight_timeout;

/**
* user hovers one image:
* create a absolute div with the same image inside,
* and append it to the body
*/
$('img.ih_image').bind('mouseenter',function () {
  var $thumb = $(this);

  var $clone = $('<div />',{
   'id'  : 'ih_clone',
   'className' : 'ih_image_clone_wrap',
   'html'      : '<img src="' + $thumb.attr('src') + '" alt="' + $thumb.attr('alt') + '"/><span></span>',
   'style'  : 'top:' + $thumb.offset().top + 'px;left:' + $thumb.offset().left + 'px;'
  });

  var highlight = function (){
   $('#ih_overlay').show();
   $('BODY').append($clone);
  }
  //show it after some time ...
  highlight_timeout = setTimeout(highlight,700);

  /**
  * when we click on the zoom,
  * we display the image in the center of the window,
  * and enlarge it to the size of the real image,
  * fading this one in, after the animation is over.
  */
  $clone.find('.ih_zoom').bind('click',function(){
   var $zoom = $(this);
   $zoom.addClass('ih_loading').removeClass('ih_zoom');
   var imgL_source = $thumb.attr('alt');

   $('<img style="display:none;"/>').load(function(){
    var $imgL = $(this);
    $zoom.hide();
    var windowW = $(window).width();
    var windowH = $(window).height();
    var windowS = $(window).scrollTop();

    $clone.append($imgL).animate({
     'top'   : windowH/2 + windowS + 'px',
     'left'   : windowW/2  + 'px',
     'margin-left' : -$thumb.width()/2 + 'px',
     'margin-top' : -$thumb.height()/2 + 'px'
    },400,function(){
     var $clone = $(this);
     var largeW = $imgL.width();
     var largeH = $imgL.height();
     $clone.animate({
      'top'   : windowH/2 + windowS + 'px',
      'left'   : windowW/2  + 'px',
      'margin-left' : -largeW/2 + 'px',
      'margin-top' : -largeH/2 + 'px',
      'width'   : largeW + 'px',
      'height'  : largeH + 'px'
     },400).find('img:first').animate({
      'width'   : largeW + 'px',
      'height'  : largeH + 'px'
     },400,function(){
      var $thumb = $(this);
      /**
      * fade in the large image and
      * replace the zoom with a cross,
      * so the user can close the preview mode
      */
      $imgL.fadeIn(function(){
       $zoom.addClass('ih_close')
         .removeClass('ih_loading')
         .fadeIn(function(){
         $(this).bind('click',function(){
          $clone.remove();
          clearTimeout(highlight_timeout);
          $('#ih_overlay').hide();
         });
        $(this).bind('click',function(){
         $clone.remove();
         clearTimeout(highlight_timeout);
         $('#ih_overlay').hide();
        });
       });
       $thumb.remove();
      });
     });
    });
   }).error(function(){
    /**
    * error loading image
    * maybe show a message like
    * 'no preview available'?
    */
    $zoom.fadeOut();
   }).attr('src',imgL_source);
  });
}).bind('mouseleave',function(){
 /**
 * the user moves the mouse out of an image.
 * if there's no clone yet, clear the timeout
 * (user was probably scolling through the article, and
 * doesn't want to view the image)
 */
 if($('#ih_clone').length) return;
 clearTimeout(highlight_timeout);
});

/**
* the user moves the mouse out of the clone.
* if we don't have yet the cross option to close the preview, then
* clear the timeout
*/
$('#ih_clone').live('mouseleave',function() {
 var $clone = $('#ih_clone');
 if(!$clone.find('.ih_preview').length){
  $clone.remove();
  clearTimeout(highlight_timeout);
  $('#ih_overlay').hide();
 }
});
And that’s all! We hope you enjoyed this tutorial and find it useful!
View demo

Download source
 

[Java Script] Beautiful Photo Stack Gallery with jQuery and CSS3

0 nhận xét
Thất Tình.Biz | Phần mềm | Tin tức | Thủ Thuật | Phim | Game|Teen Sock| Scandan


View demo
Download source
In this tutorial we are going to create a nice and fresh image gallery. The idea is to show the albums as a slider, and when an album is chosen, we show the images of that album as a beautiful photo stack. In the photo stack view, we can browse through the images by putting the top most image behind all the stack with a slick animation.
We will use jQuery and CSS3 properties for the rotated image effect. We will also use the webkit-box-reflect property in order to mirror the boxes in the album view – check out the demo in Google Chrome or Apple Safari to see this wonderful effect.
We will also use a bit of PHP for getting the images from each album.
So, let’s start!

The Markup

In our HTML structure we will have several elements. The main ones are for the album columns with thumbnail and description, and the preview with the photo stack.
The structure for the album view is going to look as follows:
<div id="ps_slider">

 <a></a>
 <a></a>

 <div id="ps_albums">

  <div style="opacity:0;">
   <img src="albums/album1/thumb/thumb.jpg" alt=""/>
   <div>
    <h2>Album title</h2>
    <span>Description text</span>
   </div>
  </div>

  <div style="opacity:0;">
   ...
  </div>

  ...
 </div> 

</div>
The opacity of the album div is going to be 0 in the beginning, we will then use JavaScript to fade in the columns.
The information that we need to provide in the HTML is the location of each album and its thumbnail images. With our little PHP script we will then get all the images from the respective album.
The structure for the dark overlay and the preview with the photo stack is going to look like this:
<div id="ps_overlay" style="display:none;"></div>

<a id="ps_close" style="display:none;"></a>

<div id="ps_container" style="display:none;">
 <a id="ps_next_photo" style="display:none;"></a>
</div>
We will dynamically insert the pictures of each album into the ps_container div.
Now, let’s take a look at the PHP.

The PHP

Our PHP file will be called from our JavaScript and we will get the information with AJAX call. The PHP looks as follows:
$location  = 'albums';
$album_name = $_GET['album_name'];
$files   = glob($location . '/' . $album_name . '/*.{jpg,gif,png}', GLOB_BRACE);
$encoded  = json_encode($files);
echo $encoded;
unset($encoded);

The CSS

The style for the gallery is going to contain some CSS3 properties and also a Webkit specific property for a mirror effect.
Let’s start by resetting some paddings and margins and defining the general style for the body:
body, ul, li, h1, h2, h3{
 margin:0;
 padding:0;
}
body{
 background:#121212;
 font-family:Arial, Helvetica, sans-serif;
 font-size:11px;
 color:#fff;
 overflow-x:hidden;
}
We will continue with the style of the preview. The overlay is going to have the following style:
.ps_overlay{
    z-index:90;
    background:#111;
    width:100%;
    height:100%;
    position:fixed;
    top:0px;
    left:0px;
    opacity:0.5;
}
The container for the photo stack will have a defined height and width. We will position it absolutely and center it with the “50%/negative margins” method:
.ps_container{
 width:480px;
 height:350px;
 position:absolute;
 top:50%;
 margin-top:-175px;
 left:50%;
 margin-left:-240px;
 z-index:100;
}
The image will have a thick white border and a nice box shadow. We will center the image relatively to its container but since we will only know the width and height of the images once we dynamically add them, we will set the margins in our JavaScript function:
.ps_container img{
 border:10px solid #fff;
 position:absolute;
 top:50%;
 left:50%;
 -moz-box-shadow:1px 1px 10px #000;
 -webkit-box-shadow:1px 1px 10px #000;
 box-shadow:1px 1px 10px #000;
}
The close button for the preview is going to be fixed at the top right of the window:
a.ps_close{
 background:#000 url(../images/close.png) no-repeat center center;
 cursor:pointer;
 width:56px;
 height:56px;
 position:fixed;
 right:10px;
 top:10px;
 z-index:1000;
 -moz-border-radius:10px;
 -webkit-border-radius:10px;
 border-radius:10px;
 opacity:0.6;
}
We will show a “next photo” element on top of the current image when the user hovers over it:
a.ps_next_photo{
 position:absolute;
 top:50%;
 left:50%;
 width:56px;
 height:56px;
 margin:-28px 0 0 -28px;
 z-index:200;
 cursor:pointer;
 background:#000 url(../images/next_photo.png) no-repeat 50% 50%;
 opacity:0.6;
    -moz-border-radius:10px;
    -webkit-border-radius:10px;
    border-radius:10px;
}
The hover classes for the last two elements:
a.ps_next_photo:hover,
a.ps_close:hover{
 opacity:0.8;
}
Now we are going to define the style for the album view and its columns. The slider container will be positioned relatively. With the auto values for the left and right margins we center the container horizontally on the page:
.ps_slider{
 width:845px;
 height:300px;
 position:relative;
 margin:110px auto 0px auto;
}
The navigation elements are going to have the following style:
.ps_slider a.next,
.ps_slider a.prev{
 position:absolute;
 background-color:#000;
    background-position:center center;
    background-repeat:no-repeat;
    border:1px solid #232323;
    width:20px;
    height:20px;
    top:50%;
    margin-top:-10px;
    opacity:0.6;
    -moz-border-radius:5px;
    -webkit-border-radius:5px;
    border-radius:5px;
    cursor:pointer;
    outline:none;
}
.ps_slider a.prev{
    left:-30px;
    background-image:url(../images/prev.png);
}
.ps_slider a.next{
    right:-30px;
    background-image:url(../images/next.png);
}
.ps_slider a.prev:hover,
.ps_slider a.next:hover{
    border:1px solid #333;
    opacity:0.9;
}
We also define a class for the navigation elements when they are disabled:
.ps_slider a.disabled,
.ps_slider a.disabled:hover{
    opacity:0.4;
    border:1px solid #111;
    cursor:default;
}
Each album column is going to have the following style:
.ps_slider .ps_album{
 width:140px;
 height:310px;
 padding:10px;
 background-color:#333;
 border:1px solid #444;
 position:absolute;
 top:0px;
 text-align:center;
 cursor:pointer;
 -moz-box-shadow:1px 1px 4px #000;
 -webkit-box-shadow:1px 1px 4px #000;
 box-shadow:1px 1px 4px #000;
 -webkit-box-reflect:
  below 5px
  -webkit-gradient(
   linear,
   left top,
   left bottom,
   from(transparent),
   color-stop(0.6, transparent),
   to(rgb(18, 18, 18))
  );
}
The last property is the Webkit box reflex that mirrors the columns. We say that it should mirror the element in a gradient like way.
We add a hover class for the whole column:
.ps_slider .ps_album:hover{
  background-color:#383838;
}
The thumbnail image and the content of the column are going to have the following styles:
.ps_slider .ps_album img{
 height:90px;
 border:1px solid #444;
 -moz-box-shadow:1px 1px 4px #000;
 -webkit-box-shadow:1px 1px 4px #000;
 box-shadow:1px 1px 4px #000;
}
.ps_slider .ps_album .ps_desc{
 display:block;
 color:#666;
 background:#111 url(../images/overlay.png) no-repeat bottom right;
 height:200px;
 margin-top:10px;
 text-align:left;
 line-height:20px;
 overflow:hidden;
 text-overflow:ellipsis;
 border:1px solid #393939;
 -moz-box-shadow:0px 0px 2px #000 inset;
 -webkit-box-shadow:0px 0px 2px #000 inset;
 box-shadow:0px 0px 2px #000 inset;
}
.ps_slider .ps_album:hover .ps_desc{
 background-image:none;
}
.ps_slider .ps_album .ps_desc span{
 display:block;
 margin:0px 10px 10px 10px;
 border-top:1px solid #333;
 padding-top:5px;
}
.ps_slider .ps_album .ps_desc h2{
 margin:10px 10px 0px 10px;
 text-align:left;
 padding-bottom:5px;
 font-weight:normal;
 color:#ddd;
 text-shadow:0px 0px 1px #fff;
 border-bottom:1px solid #000;
}
The loading element will show when we click on an album and all the images get loaded in the preview:
.ps_slider .loading{
 background:#121212 url(../images/loading.gif) no-repeat 50% 50%;
 position:absolute;
 top:0px;
 left:0px;
 width:100%;
 height:100%;
 opacity:0.7;
}
For the opacity to work in IE you need to add this filter (with the right value):
I did not want to uglify the code.
Let’s add the magic!

The JavaScript

First, we need to define some variables that help us control the album navigation and keep some elements. The variable positions saves the left value for each album column. This depends on the width of the column.
/**
* navR,navL are flags for controlling the albums navigation
* first gives us the position of the album on the left
* positions are the left positions for each of the 5 albums displayed at a time
*/
var navR,navL = false;
var first  = 1;
var positions  = {
 '0'  : 0,
 '1'  : 170,
 '2'  : 340,
 '3'  : 510,
 '4'  : 680
}
var $ps_albums   = $('#ps_albums');
/**
* number of albums available
*/
var elems   = $ps_albums.children().length;
var $ps_slider  = $('#ps_slider');
We are going to give an initial positioning to the album columns:
/**
* position all the albums on the right side of the window
*/
var hiddenRight  = $(window).width() - $ps_albums.offset().left;
$ps_albums.children('div').css('left',hiddenRight + 'px');

/**
* move the first 5 albums to the viewport
*/
$ps_albums.children('div:lt(5)').each(
 function(i){
  var $elem = $(this);
  $elem.animate({'left': positions[i] + 'px','opacity':1},800,function(){
   if(elems > 5)
    enableNavRight();
  });
 }
);
For sliding through the albums, we will define what happens when we click on the next or previous button and create two functions for moving left or right:
/**
* next album
*/
$ps_slider.find('.next').bind('click',function(){
 if(!$ps_albums.children('div:nth-child('+parseInt(first+5)+')').length || !navR) return;
 disableNavRight();
 disableNavLeft();
 moveRight();
});

/**
* we move the first album (the one on the left) to the left side of the window
* the next 4 albums slide one position, and finally the next one in the list
* slides in, to fill the space of the first one
*/
function moveRight () {
 var hiddenLeft  = $ps_albums.offset().left + 163;

 var cnt = 0;
 $ps_albums.children('div:nth-child('+first+')').animate({'left': - hiddenLeft + 'px','opacity':0},500,function(){
   var $this = $(this);
   $ps_albums.children('div').slice(first,parseInt(first+4)).each(
    function(i){
     var $elem = $(this);
     $elem.animate({'left': positions[i] + 'px'},800,function(){
      ++cnt;
      if(cnt == 4){
       $ps_albums.children('div:nth-child('+parseInt(first+5)+')').animate({'left': positions[cnt] + 'px','opacity':1},500,function(){
        //$this.hide();
        ++first;
        if(parseInt(first + 4) < elems)
         enableNavRight();
        enableNavLeft();
       });
      }
     });
    }
   );
 });
}

/**
* previous album
*/
$ps_slider.find('.prev').bind('click',function(){
 if(first==1  || !navL) return;
 disableNavRight();
 disableNavLeft();
 moveLeft();
});

/**
* we move the last album (the one on the right) to the right side of the window
* the previous 4 albums slide one position, and finally the previous one in the list
* slides in, to fill the space of the last one
*/
function moveLeft () {
 var hiddenRight  = $(window).width() - $ps_albums.offset().left;

 var cnt = 0;
 var last= first+4;
 $ps_albums.children('div:nth-child('+last+')').animate({'left': hiddenRight + 'px','opacity':0},500,function(){
   var $this = $(this);
   $ps_albums.children('div').slice(parseInt(last-5),parseInt(last-1)).each(
    function(i){
     var $elem = $(this);
     $elem.animate({'left': positions[i+1] + 'px'},800,function(){
      ++cnt;
      if(cnt == 4){
       $ps_albums.children('div:nth-child('+parseInt(last-5)+')').animate({'left': positions[0] + 'px','opacity':1},500,function(){
        //$this.hide();
        --first;
        enableNavRight();
        if(first > 1)
         enableNavLeft();
       });
      }
     });
    }
   );
 });
}
The next helper functions deal with disabling and enabling the the navigation items:
/**
* disable or enable albums navigation
*/
function disableNavRight () {
 navR = false;
 $ps_slider.find('.next').addClass('disabled');
}
function disableNavLeft () {
 navL = false;
 $ps_slider.find('.prev').addClass('disabled');
}
function enableNavRight () {
 navR = true;
 $ps_slider.find('.next').removeClass('disabled');
}
function enableNavLeft () {
 navL = true;
 $ps_slider.find('.prev').removeClass('disabled');
}
In the next steps we will define what happens when we open an album. We first make the loading element appear and show the preview after we loaded all the images. The information of the source comes from an AJAX call to our PHP class. For the rotation effect, we use the rotate CSS3 property which we restrict to a certain range of degrees, so that we don’t rotate an image crazily:
var $ps_container  = $('#ps_container');
var $ps_overlay  = $('#ps_overlay');
var $ps_close  = $('#ps_close');
/**
* when we click on an album,
* we load with AJAX the list of pictures for that album.
* we randomly rotate them except the last one, which is
* the one the User sees first. We also resize and center each image.
*/
$ps_albums.children('div').bind('click',function(){
 var $elem = $(this);
 var album_name  = 'album' + parseInt($elem.index() + 1);
 var $loading  = $('<div />',{className:'loading'});
 $elem.append($loading);
 $ps_container.find('img').remove();
 $.get('photostack.php', {album_name:album_name} , function(data) {
  var items_count = data.length;
  for(var i = 0; i < items_count; ++i){
   var item_source = data[i];
   var cnt   = 0;
   $('<img />').load(function(){
    var $image = $(this);
    ++cnt;
    resizeCenterImage($image);
    $ps_container.append($image);
    var r  = Math.floor(Math.random()*41)-20;
    if(cnt < items_count){
     $image.css({
      '-moz-transform' :'rotate('+r+'deg)',
      '-webkit-transform' :'rotate('+r+'deg)',
      'transform'   :'rotate('+r+'deg)'
     });
    }
    if(cnt == items_count){
     $loading.remove();
     $ps_container.show();
     $ps_close.show();
     $ps_overlay.show();
    }
   }).attr('src',item_source);
  }
 },'json');
});

/**
* when hovering each one of the images,
* we show the button to navigate through them
*/
$ps_container.live('mouseenter',function(){
 $('#ps_next_photo').show();
}).live('mouseleave',function(){
 $('#ps_next_photo').hide();
});
The nice animation of putting the current image at the back of our stack is defined in the following:
/**
* navigate through the images:
* the last one (the visible one) becomes the first one.
* we also rotate 0 degrees the new visible picture
*/
$('#ps_next_photo').bind('click',function(){
 var $current  = $ps_container.find('img:last');
 var r   = Math.floor(Math.random()*41)-20;

 var currentPositions = {
  marginLeft : $current.css('margin-left'),
  marginTop : $current.css('margin-top')
 }
 var $new_current = $current.prev();

 $current.animate({
  'marginLeft':'250px',
  'marginTop':'-385px'
 },250,function(){
  $(this).insertBefore($ps_container.find('img:first'))
      .css({
     '-moz-transform' :'rotate('+r+'deg)',
     '-webkit-transform' :'rotate('+r+'deg)',
     'transform'   :'rotate('+r+'deg)'
    })
      .animate({
     'marginLeft':currentPositions.marginLeft,
     'marginTop' :currentPositions.marginTop
     },250,function(){
      $new_current.css({
       '-moz-transform' :'rotate(0deg)',
       '-webkit-transform' :'rotate(0deg)',
       'transform'   :'rotate(0deg)'
      });
      });
 });
});
We animate the top and left margins with certain values that create the “putting back” effect. Since our structure always shows the last image on the top, we will also need to insert the moving image at the beginning, so that it appear as last one in the stack.
Clicking on the close element brings us back to the album view:
/**
* close the images view, and go back to albums
*/
$('#ps_close').bind('click',function(){
 $ps_container.hide();
 $ps_close.hide();
 $ps_overlay.fadeOut(400);
});
Our famous resize function resizes the image according to the given container width and height.
In the end of the function we apply the sizes and we also apply the negative margins – remember, that’s the way we can center an absolute positioned element; we defined top and left in the CSS to be 50%, so now we need to pull it to the right place with these margin values.
/**
* resize and center the images
*/
function resizeCenterImage($image){
 var theImage  = new Image();
 theImage.src  = $image.attr("src");
 var imgwidth  = theImage.width;
 var imgheight  = theImage.height;

 var containerwidth  = 460;
 var containerheight = 330;

 if(imgwidth > containerwidth){
  var newwidth = containerwidth;
  var ratio = imgwidth / containerwidth;
  var newheight = imgheight / ratio;
  if(newheight > containerheight){
   var newnewheight = containerheight;
   var newratio = newheight/containerheight;
   var newnewwidth =newwidth/newratio;
   theImage.width = newnewwidth;
   theImage.height= newnewheight;
  }
  else{
   theImage.width = newwidth;
   theImage.height= newheight;
  }
 }
 else if(imgheight > containerheight){
  var newheight = containerheight;
  var ratio = imgheight / containerheight;
  var newwidth = imgwidth / ratio;
  if(newwidth > containerwidth){
   var newnewwidth = containerwidth;
   var newratio = newwidth/containerwidth;
   var newnewheight =newheight/newratio;
   theImage.height = newnewheight;
   theImage.width= newnewwidth;
  }
  else{
   theImage.width = newwidth;
   theImage.height= newheight;
  }
 }
 $image.css({
  'width'   :theImage.width,
  'height'  :theImage.height,
  'margin-top' :-(theImage.height/2)-10+'px',
  'margin-left' :-(theImage.width/2)-10+'px'
 });
}
});
And that’s it! We hope you enjoyed this tutorial and find it useful!
P.S. Because of some Webkit properties, this demo is a really nice experience if you use a Webkit browser like Chrome or Safari. It will also be fully functional in all latest browsers like Firefox and IE (without those beautiful properties, though).
View demo

Download source
 

[Java Script] Thumbnails Navigation Gallery with jQuery

0 nhận xét
Thất Tình.Biz | Phần mềm | Tin tức | Thủ Thuật | Phim | Game|Teen Sock| Scandan


View demo
Download source
In this tutorial we are going to create an extraordinary gallery with scrollable thumbnails that slide out from a navigation. We are going to use jQuery and some CSS3 properties for the style. The main idea is to have a menu of albums where each item will reveal a horizontal bar with thumbnails when clicked. The thumbnails container will scroll automatically when the user moves the mouse to the left or right.
When a thumbnail is clicked it will be loaded as a full image preview in the background of the page. We will also have a text container for one of the menu items.
The beautiful photos are from Mark Sebastian’s photostream on Flickr. You can find all the images used in the demo in the set The “IT” Factor. Please review the Creative Commons license that is included in the demo.
So, let’s get started!

The Markup

Our HTML is mainly going to consist of a wrapper and the menu list. We will have some other elements, like the full image, the loading div and the halftone overlay. First, let’s create the wrapper:
<div id="st_main">

</div>
Inside of our wrapper we will add the following:
<img src="images/album/1.jpg" alt="" style="display:none;"/>

<div></div>

<h1>Mark Sebastian</h1>

<div id="st_loading">
 <span>Loading...</span>
</div>
The first element is our full preview image. The overlay is going to be a fixed div which will stretch over the whole screen repeating a halftone pattern to create a fancy overlay effect on the image. We also add a title and a loading div.
We then add an unordered list where each li element is going to contain a span for its title and the thumbnails wrapper. The last li element is going to contain some wrapper for text, that’s why we will not give it the class “album”. Later, in the jQuery function we will need to distinguish that.
<ul id="st_nav">
 <li>
  <span>
   Newest Collection
   <span></span>
  </span>
  <div>
   <div>
    <img src="images/album/thumbs/1.jpg" alt="images/album/1.jpg"/>
    <img src="images/album/thumbs/2.jpg" alt="images/album/2.jpg"/>
    ...
   </div>
  </div>
 </li>
 ...
 <li>
  <span>
   About
   <span></span>
  </span>
  <div>
   <div>
    <p>
     Some description
    </p>
   </div>
  </div>
 </li>
</ul>
The thumbnail images get the alt value of the path to the full size image. That might not be the proper use of the alt attribute, but it’s just so convenient for our functionality that we will use it this way.
Let’s take a look at the style.

The CSS

First, let’s reset the paddings and margins for all elements and define the general styles:
*{
 margin:0;
 padding:0;
}
body{
 font-family:"Myriad Pro","Trebuchet MS", Helvetica, sans-serif;
 font-size:16px;
 color:#fff;
 background-color:#000;
 overflow:hidden;
}
h1{
 margin:20px;
 font-size:40px;
}
Making the body overflow hidden we avoid any scroll bar appearing, but you can adapt that to your needs. I.e. if it is important that the full sized image is completely viewable by the user, you might want to remove the overflow:hidden property.
Next, we will define the style for the full size image, the overlay and the loading div:
.st_main img.st_preview{
 position:absolute;
 left:0px;
 top:0px;
 width:100%;
}
.st_overlay{
 width:100%;
 height:100%;
 position:fixed;
 top:0px;
 left:0px;
 background:transparent url(../images/pattern.png) repeat-x bottom left;
 opacity:0.3;
}
.st_loading{
 position:fixed;
 top:10px;
 right:0px;
 background:#000 url(../images/icons/loader.gif) no-repeat 10px 50%;
 padding:15px 40px 15px 60px;
 -moz-box-shadow:0px 0px 2px #000;
 -webkit-box-shadow:0px 0px 2px #000;
 box-shadow:0px 0px 2px #000;
 opacity:0.6;
}
By setting the image width to be always 100%, we make sure that it occupies all the horizontal space on the page. For very large screens the image might look pixelated which can, of course, be avoided by using gigantic images. In our demo we use a maximum width of 1600 pixel to make the loading time bearable. The halftone pattern on top of the image helps a little to disguise a pixelated effect.
Please note that whenever opacity is used, the IE filter property needs to be used if you want to achieve semi-transparent effects in IE. The overlay looks like crap if you use the filter property, though. Check out the ZIP file, I added the IE DXImageTransform filter to the respective styles.
The navigation will be positioned absolutely:
ul.st_navigation{
 position:absolute;
 width:100%;
 top:140px;
 left:-300px;
 list-style:none;
}
The initial left value is set to -300 pixel because we want to slide it in only after our full image is loaded. If you use longer titles in the list items, you might need to adapt this value.
Our list elements are going to have the following style:
ul.st_navigation li {
 float:left;
 clear:both;
 margin-bottom:8px;
 position:relative;
 width:100%;
}
The span for the title will be styled as follows:
ul.st_navigation li span.st_link{
 background-color:#000;
 float:left;
 position:relative;
 line-height:50px;
 padding:0px 20px;
 -moz-box-shadow:0px 0px 2px #000;
 -webkit-box-shadow:0px 0px 2px #000;
 box-shadow:0px 0px 2px #000;
}
Next, we define the style for the spans with the up/down arrow for opening and closing the thumbnail container:
ul.st_navigation li span.st_arrow_down,
ul.st_navigation li span.st_arrow_up{
 position:absolute;
 margin-left:15px;
 width:40px;
 height:50px;
 cursor:pointer;
 -moz-box-shadow:0px 0px 2px #000;
 -webkit-box-shadow:0px 0px 2px #000;
 box-shadow:0px 0px 2px #000;
}
ul.st_navigation li span.st_arrow_down{
 background:#000 url(../images/icons/down.png) no-repeat center center;
}
ul.st_navigation li span.st_arrow_up{
 background:#000 url(../images/icons/up.png) no-repeat center center;
}
The wrapper for the thumbnail container will be positioned absolutely and we want to hide any vertical overflow:
.st_wrapper{
 display:none;
 position: absolute;
    width:100%;
    height:126px;
    overflow-y:hidden;
 top:50px;
    left:0px;
}
Although the thumbs are only 120 pixels high, we want to leave some space so that the box shadow of the images inside will not be cut away.
The thumbnails container will simply be styled as follows:
.st_thumbs{
    height:126px;
    margin: 0;
}
The thumbnails will have a neat box shadow and some spacing:
.st_thumbs img{
    float:left;
    margin:3px 3px 0px 0px;
    cursor:pointer;
 -moz-box-shadow:1px 1px 5px #000;
 -webkit-box-shadow:1px 1px 5px #000;
 box-shadow:1px 1px 5px #000;
 opacity:0.7;
}
The st_about class is the wrapper class for the text container:
.st_about{
 display:none;
 position:absolute;
 top:50px;
    left:0px;
 opacity:0.6;
}
And, finally the text container itself:
.st_subcontent{
 background:#000;
 padding:30px;
 -moz-box-shadow:0px 0px 10px #000;
 -webkit-box-shadow:0px 0px 10px #000;
 box-shadow:0px 0px 10px #000;
}
And that’s all the style! Let’s make some magic!

The JavaScript

In our jQuery function we will first define some variables:
//the loading image
var $loader  = $('#st_loading');
//the ul element
var $list  = $('#st_nav');
//the current image being shown
var $currImage  = $('#st_main').children('img:first');
The first thing that we want to do is to load the current full size image. After it’s loaded, we want the navigation to appear:
$('<img>').load(function(){
 $loader.hide();
 $currImage.fadeIn(3000);
 //slide out the menu
 setTimeout(function(){
  $list.animate({'left':'0px'},500);
 },
 1000);
}).attr('src',$currImage.attr('src'));
The buildThumbs() function calculates the widths of all the thumbnail containers. We need that value for the automatic scrolling function later on:
buildThumbs();

function buildThumbs(){
 $list.children('li.album').each(function(){
  var $elem    = $(this);
  var $thumbs_wrapper = $elem.find('.st_thumbs_wrapper');
  var $thumbs   = $thumbs_wrapper.children(':first');
  //each thumb has 180px and we add 3 of margin
  var finalW    = $thumbs.find('img').length * 183;
  $thumbs.css('width',finalW + 'px');
  //make this element scrollable
  makeScrollable($thumbs_wrapper,$thumbs);
 });
}
Next, we define the behavior of clicking on the arrows. If it’s down, we will expand the thumbnail container and hide any other. If it’s up, we will make the current container hide again.
$list.find('.st_arrow_down').live('click',function(){
 var $this = $(this);
 hideThumbs();
 $this.addClass('st_arrow_up').removeClass('st_arrow_down');
 var $elem = $this.closest('li');
 $elem.addClass('current').animate({'height':'170px'},200);
 var $thumbs_wrapper = $this.parent().next();
 $thumbs_wrapper.show(200);
});
$list.find('.st_arrow_up').live('click',function(){
 var $this = $(this);
 $this.addClass('st_arrow_down').removeClass('st_arrow_up');
 hideThumbs();
});
Before we define the hideThumbs() function, we specify what happens when clicking on a thumb. The full size image will show and while it’s loading we will make the loading div appear. Then we animate the opacity and fade the image in:
$list.find('.st_thumbs img').bind('click',function(){
 var $this = $(this);
 $loader.show();
 $('<img/>').load(function(){
  var $this = $(this);
  var $currImage = $('#st_main').children('img:first');
  $this.insertBefore($currImage);
  $loader.hide();
  $currImage.fadeOut(2000,function(){
   $(this).remove();
  });
 }).attr('src',$this.attr('alt'));
}).bind('mouseenter',function(){
 $(this).stop().animate({'opacity':'1'});
}).bind('mouseleave',function(){
 $(this).stop().animate({'opacity':'0.7'});
});
The function to hide the thumbnails looks as follows:
function hideThumbs(){
 $list.find('li.current')
   .animate({'height':'50px'},400,function(){
   $(this).removeClass('current');
   })
   .find('.st_thumbs_wrapper')
   .hide(200)
   .andSelf()
   .find('.st_link span')
   .addClass('st_arrow_down')
   .removeClass('st_arrow_up');
}
We animate the height of the li and make the thumbnails container disappear like that. We also need to set the class for the arrow span correctly.
And finally, we will define the makeScrollable() function that automatically scrolls the thumbnails div horizontally on mouse move:
function makeScrollable($outer, $inner){
 var extra    = 800;
 //Get menu width
 var divWidth = $outer.width();
 //Remove scrollbars
 $outer.css({
  overflow: 'hidden'
 });
 //Find last image in container
 var lastElem = $inner.find('img:last');
 $outer.scrollLeft(0);
 //When user move mouse over menu
 $outer.unbind('mousemove').bind('mousemove',function(e){
  var containerWidth = lastElem[0].offsetLeft + lastElem.outerWidth() + 2*extra;
  var left = (e.pageX - $outer.offset().left) * (containerWidth-divWidth) / divWidth - extra;
  $outer.scrollLeft(left);
 });
}
For cufonizing the titles and adding some decent shadow, we will include the following into the head of our html document:
<script src="js/cufon-yui.js" type="text/javascript"></script>
<script src="js/Quicksand_Book_400.font.js" type="text/javascript"></script>
<script type="text/javascript">
 Cufon.replace('span,p,h1',{
  textShadow: '0px 0px 1px #ffffff'
 });
</script>
And that’s it! We hope you enjoyed the tutorial and find it useful!
View demo
Download source
 

[Java Script] Full Page Image Gallery with jQuery

0 nhận xét
Thất Tình.Biz | Phần mềm | Tin tức | Thủ Thuật | Phim | Game|Teen Sock| Scandan


View demo
Download source
In this tutorial we are going to create a stunning full page gallery with scrollable thumbnails and a scrollable full screen preview. The idea is to have a thumbnails bar at the bottom of the page that scrolls automatically when the user moves the mouse. When a thumbnail is clicked, it moves to the center of the page and the full screen image is loaded in the background. Now the user can move up and down and the image will get scrolled automatically, giving him the opportunity to see all of the image.
We will use some CSS3 Webkit properties to enhance the look and jQuery for the functionality.
That’s why the demo is best viewed in Webkit browsers like Google Chrome or Apple Safari.
We will be using the awesome jQuery thumbnail scroller by Malihu. Big thanks to him for this great and smooth script!
Again, we will be showing some amazing photography by Mark Sebastian. Please visit his Flickr page or his homepage for more information on his work. The images that we will be using are from “The IT Factor” photo set on Flickr.
So, let’s begin!

The Markup

The HTML consists of a main wrapper div for the gallery. Inside of that wrapper we will have the full screen image, an overlay for a nice halftone pattern effect, a loading div, the navigation items and the thumbnails bar:
<div id="fp_gallery">
 <img src="images/1.jpg" alt="" id="preview" style="display:none;"/>
 <div></div>
 <div id="fp_loading"></div>
 <div id="fp_next"></div>
 <div id="fp_prev"></div>
 <div id="outer_container">
  <div id="thumbScroller">
   <div>
    <div>
     <div><a href="#"><img src="images/thumbs/1.jpg" alt="images/1.jpg" /></a></div>
    </div>
    <div>
     <div><a href="#"><img src="images/thumbs/2.jpg" alt="images/2.jpg" /></a></div>
    </div>
    ...
   </div>
  </div>
 </div>
 <div id="fp_thumbtoggle">View Thumbs</div>
</div>
We will also add a “View Thumbnails” div that will appear when the thumbnails are hidden.
We are using (abusing) the alt attribute of the image to keep the path to the full image.
Let’s take a look at the style.

The CSS

First, we will reset the style and define some main properties for the body:
*{
 margin:0;
 padding:0;
}
body {
 background:#212121;
 overflow:hidden;
 font-family:Arial, Helvetica, sans-serif;
 text-transform:uppercase;
 color:#fff;
 font-size:10px;
}
In the following, we will define the style for the scrollable thumbs container. Most of the style is adapted from Malihu’s thumbnail scroller. We just edited some padding and margins and added a webkit reflection to the whole container:
#outer_container{
 position:fixed;
 bottom:-160px;
 margin:0px 0px 30px 0px;
 height:130px;
 padding:0;
 -webkit-box-reflect:
  below 5px -webkit-gradient(
   linear,
   left top,
   left bottom,
   from(transparent),
   color-stop(0.6, transparent),
   to(rgb(18, 18, 18))
  );
}
The bottom value of the container is negative in order to hide the thumbnails bar. When we load the page, we show the bar.
The following classes define the style of the inner elements of the thumbnail container:
#thumbScroller{
 position:relative;
 overflow:hidden;
}
#thumbScroller .container{
 position:relative;
 left:0;
}
#thumbScroller .content{
 float:left;
}
#thumbScroller .content div{
 margin:2px;
 height:100%;
}
The thumbnail images are going to have a thick white border and we will restrict their height to 120px:
#thumbScroller img,
img.clone{
 border:5px solid #fff;
 height:120px;
}
#thumbScroller a{
 padding:2px;
 outline:none;
}
The halftone pattern is shown by the overlay element which will be stretched over all the screen and move when we scroll since it is fixed:
.fp_overlay{
 width:100%;
 height:100%;
 position:fixed;
 top:0px;
 left:0px;
 background:transparent url(../images/icons/pattern2.png) repeat-x bottom left;
}
The loading div will appear whenever we click on an image and wait for the full image to load. It will be centered on the screen with the help of the “50% trick”:
.fp_loading{
 display:none;
 position:fixed;
 top:50%;
 left:50%;
 margin:-35px 0px 0px -35px;
 background:#000 url(../images/icons/loader.gif) no-repeat center center;
 width:70px;
 height:70px;
 -moz-border-radius:10px;
 -webkit-border-radius:10px;
 border-radius:10px;
 z-index:999;
 opacity:0.7;
}
The navigation elements will be styled as follows:
.fp_next,
.fp_prev{
 width:50px;
 height:50px;
 position:fixed;
 top:50%;
 margin-top:-15px;
 cursor:pointer;
 opacity:0.5;
}
.fp_next:hover,
.fp_prev:hover{
 opacity:0.9;
}
.fp_next{
 background:#000 url(../images/icons/next.png) no-repeat center center;
 right:-50px;
}
.fp_prev{
 background:#000 url(../images/icons/prev.png) no-repeat center center;
 left:-50px;
}
While the navigation items will be positioned to the left and right and centered vertically, we will position the toggle item at the bottom of the page, centered horizontally:
.fp_thumbtoggle{
 height:50px;
 background:#000;
 width:200px;
 text-align:center;
 letter-spacing:1px;
 text-shadow:1px 1px 1px #000;
 position:fixed;
 left:50%;
 margin-left:-100px;
 bottom:-50px;
 line-height:50px;
 cursor:pointer;
 opacity:0.8;
}
.fp_thumbtoggle:hover{
 opacity:1.0;
}
Hovering a div will not work in every browser and can also be done with jQuery.
And finally, the style for the full image. Here we set the width to be always 100%, filling out the complete screen. This might make the image look pixelated on large screens but we have our halftone pattern to reduce the effect :)
img.fp_preview{
 position:absolute;
 left:0px;
 top:0px;
 width:100%;
}
Now, let’s do some magic!

The JavaScript

In the head of our HTML document we will add the jQuery thumbnail scroller by Malihu. We will be using the full size, horizontal scroller with easing. That’s why we also need to include the easing script after the inclusion of the jQuery script.
In our jQuery function we will first define some variables:
//current thumb's index being viewed
var current   = -1;
//cache some elements
var $btn_thumbs = $('#fp_thumbtoggle');
var $loader  = $('#fp_loading');
var $btn_next  = $('#fp_next');
var $btn_prev  = $('#fp_prev');
var $thumbScroller = $('#thumbScroller');
Then we will call the function showThumbs which will make the thumbnail container appear from the bottom of the page:
showThumbs(2000);
Next, we will make the whole page scrollable vertically on mouse move. When a full sized image is loaded, we want this functionality to be available:
makeScrollable();
When we click on a thumbnail, a lot of things are going to happen. First, we will create a clone of the current thumbnail which will then move to the center of the page. Then we will load the full sized image and when it finished loading, we want the clone thumbnail to expand and fade out. We will also hide the thumbnails and show the “View thumbnails” button:
$thumbScroller.find('.content').bind('click',function(e){
 var $content= $(this);
 var $elem  = $content.find('img');
 //keep track of the current clicked thumb
 //it will be used for the navigation arrows
 current  = $content.index()+1;
 //get the positions of the clicked thumb
 var pos_left  = $elem.offset().left;
 var pos_top  = $elem.offset().top;
 //clone the thumb and place
 //the clone on the top of it
 var $clone  = $elem.clone()
 .addClass('clone')
 .css({
  'position':'fixed',
  'left': pos_left + 'px',
  'top': pos_top + 'px'
 }).insertAfter($('BODY'));

 var windowW = $(window).width();
 var windowH = $(window).height();

 //animate the clone to the center of the page
 $clone.stop()
 .animate({
  'left': windowW/2 + 'px',
  'top': windowH/2 + 'px',
  'margin-left' :-$clone.width()/2 -5 + 'px',
  'margin-top': -$clone.height()/2 -5 + 'px'
 },500,
 function(){
  var $theClone  = $(this);
  var ratio  = $clone.width()/120;
  var final_w  = 400*ratio;

  $loader.show();

  //expand the clone when large image is loaded
  $('<img/>').load(function(){
   var $newimg   = $(this);
   var $currImage  = $('#fp_gallery').children('img:first');
   $newimg.insertBefore($currImage);
   $loader.hide();
   //expand clone
   $theClone.animate({
    'opacity'  : 0,
    'top'   : windowH/2 + 'px',
    'left'   : windowW/2 + 'px',
    'margin-top' : '-200px',
    'margin-left' : -final_w/2 + 'px',
    'width'   : final_w + 'px',
    'height'  : '400px'
   },1000,function(){$(this).remove();});
   //now we have two large images on the page
   //fadeOut the old one so that the new one gets shown
   $currImage.fadeOut(2000,function(){
    $(this).remove();
   });
   //show the navigation arrows
   showNav();
  }).attr('src',$elem.attr('alt'));
 });
 //hide the thumbs container
 hideThumbs();
 e.preventDefault();
});
When we click on the “View thumbnails” button, we will show the thumbnails container and hide the button and the navigation elements:
$btn_thumbs.bind('click',function(){
 showThumbs(500);
 hideNav();
});

function hideThumbs(){
 $('#outer_container').stop().animate({'bottom':'-160px'},500);
 showThumbsBtn();
}

function showThumbs(speed){
 $('#outer_container').stop().animate({'bottom':'0px'},speed);
 hideThumbsBtn();
}

function hideThumbsBtn(){
 $btn_thumbs.stop().animate({'bottom':'-50px'},500);
}

function showThumbsBtn(){
 $btn_thumbs.stop().animate({'bottom':'0px'},500);
}

function hideNav(){
 $btn_next.stop().animate({'right':'-50px'},500);
 $btn_prev.stop().animate({'left':'-50px'},500);
}

function showNav(){
 $btn_next.stop().animate({'right':'0px'},500);
 $btn_prev.stop().animate({'left':'0px'},500);
}
The events for navigating through the set of images once one is loaded:
$btn_next.bind('click',showNext);
$btn_prev.bind('click',showPrev);
The next two functions will load the previous or next image and place it before the current one which will fade out:
function showNext(){
 ++current;
 var $e_next = $thumbScroller.find('.content:nth-child('+current+')');
 if($e_next.length == 0){
  current = 1;
  $e_next = $thumbScroller.find('.content:nth-child('+current+')');
 }
 $loader.show();
 $('<img/>').load(function(){
  var $newimg   = $(this);
  var $currImage   = $('#fp_gallery').children('img:first');
  $newimg.insertBefore($currImage);
  $loader.hide();
  $currImage.fadeOut(2000,function(){$(this).remove();});
 }).attr('src',$e_next.find('img').attr('alt'));
}

function showPrev(){
 --current;
 var $e_next = $thumbScroller.find('.content:nth-child('+current+')');
 if($e_next.length == 0){
  current = $thumbScroller.find('.content').length;
  $e_next = $thumbScroller.find('.content:nth-child('+current+')');
 }
 $loader.show();
 $('<img/>').load(function(){
  var $newimg   = $(this);
  var $currImage   = $('#fp_gallery').children('img:first');
  $newimg.insertBefore($currImage);
  $loader.hide();
  $currImage.fadeOut(2000,function(){$(this).remove();});
 }).attr('src',$e_next.find('img').attr('alt'));
}
And finally, the makeScrollable function which will make the page scroll when the user moves the mouse up or down:
function makeScrollable(){
 $(document).bind('mousemove',function(e){
  var top = (e.pageY - $(document).scrollTop()/2) ;
  $(document).scrollTop(top);
 });
}
And that’s it!
Don’t forget to view the demo in a Webkit browser – especially in Safari you will have a divine smoothness.
We hope you liked the tutorial and the result!
View demo

Download source
 

[HTML] Bắt đầu với HTML

0 nhận xét
Thất Tình.Biz | Phần mềm | Tin tức | Thủ Thuật | Phim | Game|Teen Sock| Scandan

Bạn cần làm gì với HTML
Bạn không cần phải dùng bất kỳ các công cụ để tìm hiểu mã HTML.
* Bạn không cần bất kỳ HTML nào biên tập
* Bạn không cần phải có máy chủ trang web
* Bạn không cần một trang web
Chỉnh sửa mã HTML
Trong hướng dẫn này chúng tôi sử dụng một trình soạn thảo văn bản thuần tuý (như Notepad) để chỉnh sửa mã HTML. Chúng tôi tin rằng đây là cách tốt nhất để tìm hiểu mã HTML.
Tuy nhiên, nhà phát triển web chuyên nghiệp thường thích HTML biên tập như FrontPage hay Dreamweaver, thay vì viết văn bản thuần tuý.
Tạo thử trang Web riêng của bạn
Nếu bạn chỉ muốn tìm hiểu HTML, bỏ qua phần còn lại của chương này.
Nếu bạn muốn tạo một bài kiểm tra trang web trên máy tính của riêng bạn, chỉ cần sao chép 3 tác phẩm dưới đây để máy tính của bạn.
(Right click vào mỗi liên kết, và chọn “mục tiêu tiết kiệm như” hoặc “là liên kết lưu”)
mainpage.htm
page1.htm
page2.htm
Sau khi bạn đã sao chép các tập tin, bạn có thể nhấp đúp vào tập tin gọi là “mainpage.htm” đầu tiên của bạn và xem trang web trong hành động.
Hãy sử dụng thử trang web của bạn Để Học
Chúng tôi đề nghị bạn thử nghiệm với tất cả mọi thứ mà bạn đã học ở  web của bạn bằng cách chỉnh sửa các tập tin với một trình soạn thảo văn bản (như Notepad).
Lưu ý: Nếu thử nghiệm của bạn trang web có chứa các thẻ HTML đánh dấu bạn có biết không, đừng hoảng sợ. Bạn sẽ được học tất cả các thông tin về chương trình kế tiếp trong chương.
Htm hoặc HTML mở rộng?
Khi bạn lưu một tệp HTML, bạn có thể sử dụng hoặc. Htm hoặc. Html mở rộng. Chúng tôi sử dụng. Htm trong ví dụ của chúng tôi. Đó là một thói quen từ quá khứ, khi các phần mềm cho phép chỉ có ba chữ cái trong tập tin mở rộng
 

[HTML] Giới thiệu HTML

0 nhận xét
Thất Tình.Biz | Phần mềm | Tin tức | Thủ Thuật | Phim | Game|Teen Sock| Scandan

Ví dụ
<html>
<body><h1> Tựa đề đầu tiên của tôi </ h1> <p> đoạn đầu tiên của tôi. </ p>
</ body>
</ html>
HTML là gì?
HTML là một ngôn ngữ để mô tả các trang web.
* HTML tắt của Hyper Text Markup Language
* HTML không phải là một ngôn ngữ lập trình, nó là một ngôn ngữ đánh dấu
* Một ngôn ngữ đánh dấu là một bộ các thẻ đánh dấu
* Đánh dấu các thẻ HTML dùng để mô tả các trang web
HTML Tags
Đánh dấu các thẻ HTML thường được gọi là thẻ HTML
* Các thẻ HTML được bao quanh bởi các góc độ từ khóa dấu ngoặc như <html>
* Các thẻ HTML thông thường đi từng cặp như <b> và </ b>
* Các từ khóa đầu tiên trong một cặp là bắt đầu từ khóa, từ khóa thứ hai là kết thúc từ khóa
*
Bắt đầu và kết thúc các thẻ này còn được gọi là thẻ mở và đóng thẻ.
HTML Văn bản = Trang Web
* HTML tài liệu mô tả các trang web
* HTML tài liệu chứa các thẻ HTML và văn bản thuần tuý
* HTML tài liệu này còn được gọi là các trang web
Mục đích của một trình duyệt web (như Internet Explorer hoặc Firefox) là mã HTML để đọc các tài liệu và hiển thị chúng như là các trang web. Các trình duyệt không hiển thị các thẻ HTML, nhưng sử dụng các thẻ để giải thích nội dung của các trang:
<html>
<body>
<h1> Tựa đề đầu tiên của tôi </ h1>
<p> đoạn đầu tiên của tôi </ p>
</ body>
</ html>
Ví dụ giải thích
* Các văn bản giữa <html> và </ html> mô tả các trang web
* Các văn bản giữa <body> và </ body> là hiển thị nội dung trang
* Các văn bản giữa <h1> và </ h1> sẽ được hiển thị như là một tiêu đề
* Các văn bản giữa <p> và </ p> sẽ được hiển thị như một đoạn
 

[HTML] Các yếu tố HTML (HTML Elements)

0 nhận xét
Thất Tình.Biz | Phần mềm | Tin tức | Thủ Thuật | Phim | Game|Teen Sock| Scandan

Dữ liệu HTML được xác định bởi yếu tố HTML.

Các yếu tố HTML

HTML là một yếu tố tất cả mọi thứ từ các từ khóa bắt đầu vào cuối từ khóa:
Bắt đầu từ khóa * Element Cuối nội dung từ khóa *
<p> Đây là một đoạn </ p>
<a href=”default.htm”> Đây là một liên kết </ a>
<br />
* Bắt đầu từ khóa thường được gọi là thẻ mở từ khóa. Kết thúc từ khóa thường được gọi là thẻ đóng.
HTML tử cú pháp
* Một yếu tố HTML bắt đầu với một đầu từ khóa / mở  từ khóa
* Một yếu tố mã HTML kết thúc với một kết thúc từ khóa / đóng cửa từ khóa
* Các yếu tố nội dung là tất cả mọi thứ giữa bắt đầu và kết thúc từ khóa
* Một số yếu tố mã HTML có nội dung không có sản phẩm nào
* Yếu tố trống là yếu tố đóng trong các từ khóa bắt đầu
* Hầu hết các mã HTML có thể có các yếu tố thuộc tính
(Bạn sẽ được học về các yếu tố thuộc tính trong chương kế tiếp của hướng dẫn này)

Các yếu tố lồng nhau HTML

Hầu hết các mã HTML yếu tố có thể được lồng nhau (có thể chứa các thành phần HTML).
HTML lồng nhau, bao gồm các tài liệu HTML thành phần.
Ví dụ tài liệu HTML
<html>
<body>
<p> Đây là đoạn đầu tiên của tôi </ p>
</ body>
</ html>
Ví dụ trên có chứa 3 thành phần mã HTML.
Ví dụ đa giải thích
Các <p> yếu tố:
<p> Đây là đoạn đầu tiên của tôi </ p>
Các <p> yếu tố xác định một đoạn mã HTML trong tài liệu
Các yếu tố có một từ khóa <p> bắt đầu và kết thúc một từ khóa </ p>
Các yếu tố nội dung là: Đây là đoạn đầu tiên của tôi
Các <body> yếu tố:
<body>
<p> Đây là đoạn đầu tiên của tôi </ p>
</ body>
<body> Định nghĩa các yếu tố trong cơ thể của các tài liệu HTML
Các yếu tố có một <body> bắt đầu từ khóa và một thẻ kết thúc </ body>
Các yếu tố nội dung là một yếu tố mã HTML (một đoạn)
Các <html> yếu tố:
<html>
<body>
<p> Đây là đoạn đầu tiên của tôi </ p>
</ body>
</ html>
Các yếu tố xác định <html> toàn bộ tài liệu HTML.
Các yếu tố có một từ khóa <html> bắt đầu và kết thúc một từ khóa </ html>
Các yếu tố nội dung mã HTML là một yếu tố (cơ thể)
Không Quên các Cuối Từ khóa
Hầu hết các trình duyệt HTML sẽ hiển thị một cách chính xác, ngay cả nếu bạn quên mất những từ khóa kết thúc:
<p> Đây là một đoạn
<p> Đây là một đoạn
Ví dụ trên sẽ làm việc trong hầu hết các trình duyệt, nhưng không dựa vào nó. Quên cuối cùng từ khóa có thể sản xuất các kết quả bất ngờ hoặc các lỗi.
Lưu ý: Tương lai phiên bản của mã HTML sẽ không cho phép bạn bỏ qua các thẻ kết thúc.
Các yếu tố không có sản phẩm nào HTML
Yếu tố HTML  mà không có nội dung không có sản phẩm nào được gọi là yếu tố. Trống rỗng, yếu tố có thể được đóng trong các từ khóa bắt đầu.
<br> là một yếu tố không có sản phẩm nào mà không có một thẻ đóng (nó định nghĩa một dòng break).
Trong XHTML, XML, và trong tương lai phiên bản của mã HTML, tất cả các yếu tố phải được đóng lại.
Việc thêm một slash để bắt đầu từ khóa, như <br />, đúng là cách để đóng  trống rỗng, thành phần, chấp nhận của mã HTML, XHTML và XML.
Thậm chí nếu <br> hoạt động trong tất cả các trình duyệt, thay vì viết <br /> bằng chứng là nhiều hơn trong tương lai.
HTML Mẹo: Hãy sử dụng Chữ thường Tags
Các thẻ HTML không phải là trường hợp nhạy cảm: <P> có nghĩa là giống như <p>. Rất nhiều các trang web sử dụng chữ hoa thẻ HTML trong các trang của họ.
Chữ thường sử dụng thẻ do World Wide Web Consortium (W3C) đề nghị nên chữ thường trong HTML 4, nhu cầu sử dụng và thẻ chữ thường trong tương lai phiên bản của (X) HTML.
 

[HTML] Cấu trúc cơ sở HTML

0 nhận xét
Thất Tình.Biz | Phần mềm | Tin tức | Thủ Thuật | Phim | Game|Teen Sock| Scandan

Các trang Web khác nhau, tẻ nhạt hay sinh động, vô nghĩa hoặc rất cần thiết, nhưng tất cả đều có cùng một cấu trúc cơ sở, nên đa số các trình duyệt đang chạy trên hầu hết các kiểu máy tính đều có thể hiển thị thành công hầu hết các trang Web.
Các tập tin HTML luôn bắt đầu bằng thẻ . Thẻ này không làm gì khác ngoài nhiệm vụ báo cho trình duyệt Web biết rằng nó đang đọc một tài liệu có chứa các mã HTML. Tương tự, dòng cuối trong tài liệu của bạn luôn luôn là thẻ , tương đương như Hết.
Chi tiết kế tiếp trong catalog thẻ HTML dùng để chia tài liệu thành hai phần: đầu và thân.
Phần đầu giống như lời giới thiệu cho trang. Các trình duyệt Web dùng phần đầu này để thu nhặt các loại thông tin khác nhau về trang. Để xác định phần đầu, bạn đưa thêm thẻ và thẻ vào ngay sau thẻ . Mặc dù bạn có thể đặt một số chi tiết bên trong phạm vi phần đầu này, nhưng phổ biến nhất là tên trang. Nếu có ai đó xem trang này trong browser, thì tên trang sẽ xuất hiện trong dải tên của cửa sổ browser. Để xác định tên trang, bạn đặt đoạn văn bản tên đó giữa các thẻ . Ví dụ nếu bạn muốn tên trang của mình là My Home Sweet Home Page, bạn đưa nó vào như sau:
Phần thân là nơi bạn nhập vào các văn bản sẽ xuất hiện trên trang Web lẫn các thẻ khác quy định dáng vẻ của trang. Để xác định phần thân, bạn đặt các thẻ và sau phần đầu (dưới ).
Các thẻ sau đây xác định cấu trúc cơ bản của mọi trang Web:
Các thẻ tiêu đề khác
Văn bản và các thẻ của trang Web
 

[HTML] Bổ sung định dạng và các tiêu đề trong html

0 nhận xét
Thất Tình.Biz | Phần mềm | Tin tức | Thủ Thuật | Phim | Game|Teen Sock| Scandan

HTML bao gồm nhiều thẻ làm đẹp cho văn bản trong trang. Bạn đã thấy ở trên, một từ hoặc một câu sẽ hiện thành dạng chữ đậm như thế nào khi được đặt vào giữa các thẻ <B> và </B>. Bạn cũng có thể biểu hiện văn bản theo kiểu chữ nghiêng bằng cách bao chúng lại bằng các thẻ <I> và </I>, và làm cho các từ xuất hiện ở dạng cách đơn với các thẻ <TT> và </TT>.
Giống như các chương sách, nội dung của nhiều trang Web được chia thành các đoạn. Để giúp phân cách các đoạn này và làm cho dễ đọc hơn, bạn có thể sử dụng tiêu đề. Lý tưởng nhất, các tiêu đề này phải có tác dụng như là những đề mục nhỏ, thể hiện ý tưởng tóm tắt về đoạn văn đó. Để làm cho các đề mục này nổi bật, HTML có 6 loại thẻ tiêu đề để hiển thị văn bản theo phông chữ đậm với nhiều cỡ chữ khác nhau, từ ứng với phông lớn nhất đến ứng với phông nhỏ nhất.
 

[HTML] Làm việc với các liên kết siêu văn bản (HTML)

0 nhận xét
Thất Tình.Biz | Phần mềm | Tin tức | Thủ Thuật | Phim | Game|Teen Sock| Scandan

Thẻ HTML dùng để thiết lập các liên kết siêu văn bản là <A> và </A>. Thẻ <A> hơi khác so với các thẻ khác mà bạn đã gặp vì bạn không thể dùng nó một mình mà phải kèm thêm địa chỉ của tài liệu bạn muốn liên kết. Sau đây là cách hoạt động của nó:
<AHREF=Address>
HREF là viết tắt của hypertext reference (tham chiếu siêu văn bản). Chỉ cần thay từ địa chỉ bằng địa chỉ thực của trang Web mà bạn muốn dùng để liên kết . Dưới đây là một ví dụ:
<AHREF=http://www/dosword.com/dosworld/index.html>
Như vậy còn chưa kết thúc. Tiếp theo, bạn phải cung cấp một số văn bản diễn giải liên kết để nhấn chuột vào đó. Công việc còn lại là chèn văn bản vào giữa các thẻ <A> và </A> như sau:
<AHREF=address> Văn bản liên kết </A>
Sau đây là một ví dụ :
Why not head to the <AHREF=http://www.dosworld.com/dosworld/index.html>DOSWorld home page</A>?
 

[HTML] Chèn hình trong HTML

0 nhận xét
Thất Tình.Biz | Phần mềm | Tin tức | Thủ Thuật | Phim | Game|Teen Sock| Scandan

Nếu bạn muốn Web site của mình nổi trội hơn, bạn phải theo xu hướng đồ hoạ với các hình ảnh được chọn kỹ lưỡng. Làm thế nào để chèn hình vào trong khi các tập tin HTML chỉ có văn bản? Nhờ bổ sung thẻ <IMG> vào tài liệu, nó sẽ ra lệnh Chèn một hình vào đây. Thẻ này xác định tên của tậ tin đồ hoạ để trình duyệt có thể mở tập tin đó và hiển thị các hình:
<IMG SRC=filename>
ở đây, SRC là viết tắt của source (nguồn) và tên tập tin là tên và đường dẫn của tập tin đồ hoạ mà bạn muốn hiển thị (dùng dạng GIF hoặc JPG). Giả sử bạn có một hình tên là logo.gif nằm trong thư mục Graphics. Để đưa nó vào trang Web, bạn dùng dòng sau đây.
<IMG SRC=Graphics/logo.gif>
 

[HTML] Xuống dòng và chia đoạn trong trang HTML

0 nhận xét
Thất Tình.Biz | Phần mềm | Tin tức | Thủ Thuật | Phim | Game|Teen Sock| Scandan

Khi bạn đánh máy một văn bản trong một chương trình soạn thảo văn bản nào đó, bạn có thể chỉ cần bấm phím Return để kết thúc một dòng hay một đoạn văn, nhưng bạn sẽ cần phải làm nhiều thao tác hơn khi bạn muốn phân định riêng các đoạn văn khác nhau trong một trang Web. Browser tự động bỏ qua các mã xuống dòng bình thường. Vì vậy bạn phải viết thêm thẻ <P> để phân đoạn hay viết thẻ <BR> tại vị trí cụ thể mà bạn muốn xuống dòng.
Mã nguồn (với đoạn văn bản sử dụng mã xuống dòng bình thường)
Cộng hoà xã hội chủ nghĩa Việt nam
Độc lập – Tự do – Hạnh phúc
Đơn xin việc
Kết quả
Cộng hoà xã hội chủ nghĩa Việt namĐộc lập – Tự do – Hạnh phúcĐơn xin việc
Mã nguồn (có sử dụng thẻ <BR> và <P>)
Cộng hoà xã hội chủ nghĩa Việt nam<BR>
Độc lập – Tự do – Hạnh phúc<P>
Đơn xin việc
Kết quả
Cộng hoà xã hội chủ nghĩa Việt nam
Độc lập – Tự do – Hạnh phúc
Đơn xin việc
 

[HTML] Danh sách trong html (list)

0 nhận xét
Thất Tình.Biz | Phần mềm | Tin tức | Thủ Thuật | Phim | Game|Teen Sock| Scandan

Danh sách có trật tự
Danh sách có trật tự tự động đánh số từng thành tố của danh sách.
Mã nguồn Kết quả
<OL>
<LI>Yếu tố 1
<LI>Yếu tố 2
<LI>Yếu tố 3
</OL>
1. Yếu tố 1 2. Yếu tố 2
3. Yếu tố 3
Danh sách không có trật tự
Danh sách không  có trật tự đánh dấu (chẳng hạn các núm tròn) cho từng yếu tố của danh sách.
Mã nguồn Kết quả
<UL>
<LI>Yếu tố 1
<LI>Yếu tố 2
<LI>Yếu tố 3
</UL>
o Yếu tố 1 o Yếu tố 2
o Yếu tố 3
Danh sách định nghĩa
Mỗi yếu tố của danh sách bao gồm hai thành phần:
Tiêu đề được căn lề phía trái (chỉ ra bởi thẻ <DT>)
Phần giải nghĩa được căn lề thụt hơn sang phía phải (chỉ ra bởi thẻ <DD>)
Mã nguồn Kết quả
<DL>
<DT>Yếu tố 1
<DD>Chú giải cho yếu tố 1
<DT>Yếu tố 2
<DD>Chú giải cho yếu tố 2
</DL>
Yếu tố 1 Chú giải cho yếu tố 1
Yếu tố 2
Chú giải cho yếu tố 2
Danh sách kiểu thực đơn
Mỗi yếu tố của danh sách được cấp một chỉ số chẳng hạn như dấu tròn. Trông rất giống danh sách không có trật tự
Mã nguồn Kết quả
<MENU>
<LI>Yếu tố 1
<LI>Yếu tố 2
<LI>Yếu tố 3
</MENU>
  • · Yếu tố 1
  • · Yếu tố 2
  • · Yếu tố 3
Danh sách kiểu thư mục
Trông khá giống danh sách không có trật tự
Tổ hợp các kiểu danh sách
Ta có thể tổ hợp các kiểu danh sách với nhau