google+javascriptbanktwitter@js_bankfacebook@jsbankrss@jsbank






Hướng dẫn xây dựng phòng trưng bày ảnh với hai kiểu hiển thị Hôm nay trong bài viết này, jsB@nk xin phép được hướng dẫn bạn cách thức để xây dựng một Phòng trưng bày ảnh với hai kiểu hiển thị - một hiệu ứng JavaScript khá độc đáo để tạo một không gian trưng bày ảnh rất ấn tượng trên trang web. Bạn vui lòng vào trang chi tiết để xem thêm.


Miễn phí web hosting 1 năm đầu tại iPage



Nếu bạn vẫn còn đang tìm kiếm một nhà cung cấp hosting đáng tin cậy, tại sao không dành chút thời gian để thử với iPage, chỉ với không quá 40.000 VNĐ/tháng, nhưng bạn sẽ được khuyến mãi kèm với quà tặng trị giá trên 10.000.0000 VNĐ nếu thanh toán cho 24 tháng ~ 900.000 VNĐ?

Có trên 1 triệu khách hàng hiện tại của iPage đã & đang hài lòng với dịch vụ, tuyệt đối chắc chắn bạn cũng sẽ hài lòng giống họ! Quan trọng hơn, khi đăng ký sử dụng web hosting tại iPage thông qua sự giới thiệu của chúng tôi, bạn sẽ được hoàn trả lại toàn bộ số tiền bạn đã sử dụng để mua web hosting tại iPage. Wow, thật tuyệt vời! Bạn không phải tốn bất kì chi phí nào mà vẫn có thể sử dụng miễn phí web hosting chất lượng cao tại iPage trong 12 tháng đầu tiên. Chỉ cần nói chúng tôi biết tài khoản của bạn sau khi đăng ký.

Nếu muốn tìm hiểu thêm về ưu / nhược điểm của iPage, bạn hãy đọc đánh giá của ChọnHostViệt.com nhé!
Thử iPage miễn phí cho năm đầu tiên NGAY

Today, I would like to go over a quick and simple way to allow your users to switch page layouts by using CSS and jQuery.

Today's web users expect web pages to be increasingly more interactive. To this end, the ability to change page layouts provides your users with a more immersive experience and allows them to consume information more easily, either with a quick gallery view, or a detailed summary view.

Display Switch Tutorial:

View Demo of Display Switch

Step1. Creating the Wireframe

We will first start out designing the vertical list layout with a simple unordered list which we will use as our columns/rows.

HTML

<ul class="display">
    <li></li>
    <li></li>
    <li></li>
</ul>

CSS
*Note I used different shades of grey to achieve the subtle bevel look.

ul.display li a {
    color: #e7ff61;
    text-decoration: none;
}
ul.display li .content_block {
    padding: 0 10px;
}
ul.display li .content_block h2 {
    margin: 0;
    padding: 5px;
    font-weight: normal;
    font-size: 1.7em;
}
ul.display li .content_block p {
    margin: 0;
    padding: 5px 5px 5px 245px;  /*--The left padding keeps the
content from flowing under the image--*/

    font-size: 1.2em;
}
ul.display li .content_block a img{ /*--Double border technique--*/
    padding: 5px;
    border: 2px solid #ccc;
    background: #fff;
    margin: 0 15px 0 0;
    float: left;
}

Step2. Styling the Content

Inside of each list item, we nest a div which will act as our container of the content inside. I feel it's easier to calculate the columns when you don't have to consider the margin and padding within. This comes in handy especially when you are working with a liquid layout (since we know % and fixed pixels don't mix in too well).

HTML

<li>
        <div class="content_block">
            <a href="#"><img src="sample.gif" alt="" /></a>
            <h2><a href="#">Image Name</a></h2>
            <p>Description goes here</p>
        </div>
    </li>

CSS

ul.display li a {
    color: #e7ff61;
    text-decoration: none;
}
ul.display li .content_block {
    padding: 0 10px;
}
ul.display li .content_block h2 {
    margin: 0;
    padding: 5px;
    font-weight: normal;
    font-size: 1.7em;
}
ul.display li .content_block p {
    margin: 0;
    padding: 5px 5px 5px 245px;  <span style="color: #777;">/*--The left padding keeps the
content from flowing under the image--*/
</span>
    font-size: 1.2em;
}
ul.display li .content_block a img{ <span style="color: #777;">/*--Double border technique--*/</span>
    padding: 5px;
    border: 2px solid #ccc;
    background: #fff;
    margin: 0 15px 0 0;
    float: left;
}

Step3. Creating the Secondary View Option

Now its time to style the second display option which are in columns flowing horizontally.

Adding jQuery

CSS

ul.thumb_view li{ width: 250px; } <span style="color: #777;">/*--Switch the width
to accommodate for the three column layout--*/
</span>
ul.thumb_view li h2 { display: inline; }
ul.thumb_view li p{ display: none; }
ul.thumb_view li .content_block a img { margin: 0 0 10px; }

Step4. Creating the Switch

Time to wrap up this tutorial by creating the switch.

Switch Button

HTML

<a href="#" class="switch_thumb">Switch Display</a>

CSS
Using the 'CSS Sprites' technique, I create the link button.

a.switch_thumb {
    width: 122px;
    height: 26px;
    line-height: 26px;
    padding: 0;
    margin: 10px 0;
    display: block;
    background: url(switch.gif) no-repeat;
    outline: none;
    text-indent: -9999px;
}
a.swap { background-position: left bottom; }

I didn't feel like creating a hover state on the image, so I'll just use the opacity to dim it down a tad bit once hovered over.

a:hover.switch_thumb {
    filter:alpha(opacity=75);
    opacity:.75;
    -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=75)";
}

jQuery
At last, we'll activate the switch with a little bit of jQuery.

<script type="text/javascript">
$(document).ready(function(){

    $("a.switch_thumb").toggle(function(){
        $(this).addClass("swap");
        $("ul.display").fadeOut("fast", function() {
            $(this).fadeIn("fast").addClass("thumb_view");
        });
    }, function () {
        $(this).removeClass("swap");
        $("ul.display").fadeOut("fast", function() {
            $(this).fadeIn("fast").removeClass("thumb_view");
        });
    });

});
</script>

Final View

View Demo of Display Switch

Now Go and Experiment!

This method can be applied to many scenarios, so I would like to encourage you to experiment with this technique. If you have any other tricks to add on, please feel free to drop your comments!

iPhoneKer.com
Save up to 630$ when buy new iPhone 15

GateIO.gomymobi.com
Free Airdrops to Claim, Share Up to $150,000 per Project

https://tooly.win
Open tool hub for free to use by any one for every one with hundreds of tools

chatGPTaz.com, chatGPT4.win, chatGPT2.fun, re-chatGPT.com
Talk to ChatGPT by your mother language

Dall-E-OpenAI.com
Generate creative images automatically with AI

AIVideo-App.com
Render creative video automatically with AI

JavaScript theo ngày


Google Safe Browsing McAfee SiteAdvisor Norton SafeWeb Dr.Web