Thursday, 23 January 2014

10 jQuery snippets every designer should know

jQuery is used on thousands upon thousands of web pages. It’s one of the most common libraries to insert into pages, and it makes DOM manipulation a snap.
Of course, part of jQuery’s popularity is its simplicity. It seems we can do almost anything we like with this powerful library.
For all the options open to us, there are some snippets we tend to come back to time and time again. Today I’d like to give you 10 snippets that everyone, newbies to gurus, will use time and time again.

1) Back to top button

// Back To Top
$('a.top').click(function(){
$(document.body).animate({scrollTop : 0},800);
return false;
});
//Create an anchor tag
<a class=”top” href=”#”>Back to top</a>
As you can see using the animate and scrollTop functions in jQuery we don’t need a plugin to create a simple scroll to top animation.
By changing the scrollTop value we can change where we want the scrollbar to land, in my case I used a value of 0 because I want it to go to the very top of our page, but if I wanted an offset of 100px I could just type 100px in the function.
So all we are really doing is animating the body of our document throughout the course of 800ms until it scrolls all the way to the top of the document.

2) Checking if images are loaded

$(‘img’).load(function() {
console.log(‘image load successful’);
});
Sometimes you need to check if your images are fully loaded in order to continue with your scripts, this three line jQuery snippet can do that for you easily.
You can also check if one particular image has loaded by replacing the img tag with an ID or class.

3) Fix broken images automatically

$('img').error(function(){
$(this).attr('src', ‘img/broken.png’);
});
Occasionally we have times when we have broken image links on our website and replacing them one by one isn’t easy, so adding this simple piece of code can save you a lot of headaches.
Even if you don’t have any broken links adding this doesn’t do any harm.

4) Toggle class on hover

$(‘.btn').hover(function(){
$(this).addClass(‘hover’);
}, function(){
$(this).removeClass(‘hover’);
}
);
We usually want to change the visual of a clickable element on our page when the user hovers over and this jQuery snippet does just that, it adds a class to your element when the user is hovering and when the user stops it removes the class, so all you need to do is add the necessary styles in your CSS file.

5) Disabling input fields

$('input[type="submit"]').attr("disabled", true);
On occasion you may want the submit button of a form or even one of its text inputs to be disabled until the user has performed a certain action (checking the “I’ve read the terms” checkbox for example) and this line of code accomplishes that; it adds thedisabled attribute to your input so you can enable it when you want to.
To do that all you need to do is run the removeAttr function on the input with disabled as the parameter:
$('input[type="submit"]').removeAttr("disabled”);

6) Stop the loading of links

$(‘a.no-link').click(function(e){
e.preventDefault();
});
Sometimes we don’t want links to go to a certain page or even reload it, we want them to do something else like trigger some other script and in that case this piece of code will do the trick of preventing the default action.

7) Toggle fade/slide

// Fade
$( “.btn" ).click(function() {
$( “.element" ).fadeToggle("slow");
});
// Toggle
$( “.btn" ).click(function() {
$( “.element" ).slideToggle("slow");
});
Slides and Fades are something we use plenty in our animations using jQuery, sometimes we just want to show an element when we click something and for that the fadeIn and slideDown methods are perfect, but if we want that element to appear on the first click and then disappear on the second this piece of code will work just fine.

8) Simple accordion

// Close all Panels
$('#accordion').find(‘.content').hide();
// Accordion
$('#accordion').find(‘.accordion-header').click(function(){
var next = $(this).next();
next.slideToggle('fast’);
$(‘.content’).not(next).slideUp('fast’);
return false;
});
By adding this script all you really need to on your page is the necessary HTML go get this working.
As you can see in this snippet I firstly closed all the panels in our accordion and then on the click event I made the content that is linked to that header slide toggle , and all the other ones slide up. It’s a simple method for a quick accordion.

9) Make two divs the same height

$(‘.div').css('min-height', $(‘.main-div').height());
Sometimes you want two divs to have the same height no matter what content they have in them, this little snippet enables just that; in this case it sets the min-heightwhich means that it can be bigger than the main div but never smaller. This is great for masonry like websites.

10) Zebra stripped unordered list

$('li:odd').css('background', '#E8E8E8’);
With this little snippet you can easily create zebra striped unordered lists, this places the background you define on every odd list item so that you can place the default one for the even ones in your CSS file. You can add this snippet to any type of markup, from tables to plain divs, anything you want to be zebra stripped.

Conclusion

These are the pieces of jQuery code I find myself using again and again in my projects. I hope you bookmark this page and come back whenever you need one of these snippets.

How to learn more in 2014

Albert Einstein once said, “Any fool can know. The point is to understand.” It’s one thing to be aware of what’s new in web design, quite another to be in the thick of it actually producing usable designs that solve problems.
To keep up in this industry, You need a heightened sense of curiousity and a desire to keep learning.
As a user-centered designer, I literally spend half of my days meeting with stakeholders, peers, and subject matter experts. Finding enough quiet time just to deliver what’s expected of me consumes the remainder of my day. But this is the career I’ve chosen (I might argue it’s chosen me) — I enjoy solving problems, love design, and am captivated by technology, so I’m not sure I ever had a choice to be honest. But for any of us, keeping our skills current as technology changes can be challenging.
As the Kano Model reminds us, today’s delights rapidly transform into tomorrow’s minimum expectations from users.
learning_001
It’s not easy keeping up. Factor in family life, hanging with friends, watching the big game, or whatever your guilty pleasure may be at the time, and you have a constant deluge of competing forces vying for whatever “me time” remains. And then there’s that other thing called sleep that nobody has (yet) figured out how to achieve.
So what’s your secret, or not so secret, weapon? What’s in your go-to arsenal. How do you stay current? Do you read, watch videos, listen to podcasts, experiment with code, or a little of all of the above?
Let me start by sharing what has worked for me personally, and in turn invite you to reveal where you go when you need to stay up to date.
I’m aware that there are many resources out there that I have yet to try, such as Adobe TV, Code Academy, Tuts+, Code School, and others. So don’t take offense if one of your favorites isn’t on my personal go-to list. I intend to eventually check all those out, but you know what they say about good intentions.
learning_002
Two of my longtime favorites are lynda.com and teamtreehouse.com depending on which side of my brain I’m using. Both offer courses for design and coding, but for my money (or my employer’s money as they’re footing the bill), I’m turning toward lynda.com for my creative, artistic right brain, while leaning on Treehouse for my left brained logical analytical side.
learning_003
One of my favorites on lynda.com is Deke’s Techniques, an ongoing collection of Photoshop and Illustrator projects that can be completed in ten minutes or less. But I also rely on lynda.com for full on courses, such as the nearly four-hour long Edge Animate Essential Training, which takes you from an overview of the interface all the way through publishing. Likewise, Luke Wroblewski’s Web Form Design Best Practicesreally opened my eyes to why forms matter and some savvy techniques behind form design. I’ve also turned to lynda.com for more technical tutorials, such as iOS SDK Essential Training.
learning_004
As I alluded to earlier, teamtreehouse.com is my home when I want to get my hands a little bit dirty. Although, still providing very high quality video tutorials like lynda.com, Treehouse’s presentations carry a much more quirky vibe in the way they engage the viewer. Sometimes it comes across as a bit much for my taste, but the quality of the content is ultimately my main concern, which is very good. For example, to contrast their iOS Foundations tutorial to the equivalent on lynda.com, what I love about Treehouse are the code challenges and quizzes. What I’ve found, personally, is that I have a tendency to nod along while watching a tutorial, saying “yep I get it.” But Treehouse presents code challenges throughout a tutorial that really test your knowledge, and it’s usually at that point in time I realize I really didn’t get it at all like I thought I had.
learning_005
Treehouse has also gamified the learning experience for subscribers. You earn badges as you complete various tasks, tutorials, and adventures where you can see how you rank amongst your peers. For instance, I’m number 2 on my group standings amongst my collegues at work. The fact that I even know that proves the method behind their madness works on at least one of us. They also enable you to share your achievements via social media if you’re into braggadocio, which I never realized before, but apparently I am.
Not to be outdone, Lynda offers certificates of course completion that you can print out or even email, although I’m not sure how much, if any, weight that carries with your current or potential employers contrary to what lynda.com may want you to believe.
In my opinion, you can have all the degrees or certificates or badges that you want, but in the end it comes down being able to produce something. And that’s exactly why I love codepen.io. Codepen is a front-end sandbox whose motto is “Demo or it didn’t happen” where people can view and rate your demos or even provide feedback.
learning_006
I use Codepen on multiple fronts. First, it’s a terrific source of HTML/CSS/JS inspiration. There’s a ton of awesome demos that leave you thinking: I never knew that was even possible with CSS or HTML. How did they do that??
Second of all, it’s a great way to reverse engineer something you like. Granted, it’s not a tutorial site, but all of the code used for each demo is interactive where you can literally play with it and test out other people’s work to learn what does what. Or if you prefer, like GitHub, you can fork it and extend someone else’s demo in a new direction.
And last but certainly not least, it’s just a great way to practice. It offers tons of resources you can tap into, such as CSS preprocessors like Sass, LESS, and Stylus. With the click of a checkbox you can also choose to write prefix-free code or normalize your CSS. Have an external stylesheet, script or even just something from another “pen” you’d like to link to? Not a problem. If you prefer, write your code using CoffeeScript or LiveScript. You can even link to an external library such as jQuery, Zepto, MooTools, YUI and others with the click on a button. Still not finding the one you want? No fear, you’ll probably find it in the CDNJS library to which Codepen allows you to externally link. For what it’s worth, I look at Codepen as the holy grail of front-end experimentation.
So let’s see, I’ve got more video tutorials than I can handle, and I have my sandbox. What else could I want?
Well, one of my favorite passtimes is reading magazines, and two of my all-time favorites happen to be .NET Magazine and Web Designer, which both offer iPad subscriptions. In either publication, you’ll find terrific interviews with insanely creative people and tons of amazing tutorials each month. I get excited with every new release to say the least.
learning_007
Add in Chris Coyier’s CSS-Tricks and Luke Wroblewski’s lukew.com, and I’d argue that 24 hours isn’t enough time in the day to fit all of this in, at least not for me.
So there you have it, my repository of “expert-ness” that I turn to for education, inspiration, experimentation, and general insight from people just like you all around the world.

Was Milton Glaser right about computers destroying design?

In a previous article, I wrote about design before computers became commonplace in the design industry. A fun look back at the days of toxic chemicals and scalpel-sharp cutting tools.
The number of social media shares and tweets showed people were either nostalgic about those days not so long gone by, or fascinated by the process involved in non-electric designing. Where, however, has the computer led us? Is it a slice of Heaven or does it byte?
I was a student of some incredible designers, but Milton Glaser, whose course I admittedly never finished, still stands out in my mind. He was not a proponent of computers for design and while we young designers using computers with Photoshop 1.5 (2.0 had LAYERS!) were confused by his dislike of computers, reasoning they were faster and cheaper for design production, he stood fast. It caused us to suspect his teaching was obsolete. I hope Milton forgives me for that statement as I was young and foolish.
Years later I was reading a blog rant where some designer was blasting Glaser for saying something about the computer being to design as a microwave is to gourmet cooking. Ah-HA! That’s when it hit me. Milton, more mumbling about his dislike of computers, truly saw the future of design. He just didn’t put it in a way that made sense. A quote with a moral or haiku would have been nice!

The biggest change

Unfortunately for Glaser’s comparison, there are too many people who actually believe that a gourmet meal can be cooked in a microwave in just four minutes. There are also those who believe having Adobe CC is as good as a diploma from design school. How did Glaser see it so soon as the technology was so young? Was it the students who floated past him in his class? Every student had to show him a portfolio to be accepted into his class. Once class started, it was obvious he was really casting a season of The Real World: Art School. 
I guess he just knew what the computer, as a tool, would mean to design. It was a crutch for those who couldn’t keep up with the pack. While devotees of Leonardo are practicing drawing perfect freehand circles, there are others who create a perfect circle with a click. Is one person obsolete? Is another person using technology to their full advantage? Is one person right and another wrong?
There is no denying that the current state of personal technology has brought design tools into the hands of the public. From pre-school drawing games and puzzles to the functions adults use to make birthday announcements and garage sale flyers, everyone has seen that design is easy and we are overpaid jerks.
Computer Monster
There are those who study the functions of software, skipping color theory, typography, design history and other classes forced upon art students with the purpose of knocking pre-conceived notions out of near-empty heads so they can absorb lessons on creativity and explore the possibilities of design, and they still consider themselves “designers.”

The biggest gain

I’ve always had a terrible eye for right angles. I can’t center anything and using one of those clear blue rulers with picas to inches and everything in between, just never worked for me. Anything that was being used as the layout board that had a grid printed on it (which were most boards), was my only chance at surviving those few years before the computer became my eyes and shaking hands. I blame the chemicals.
The layout functions of design programs have made it a breeze to pump out an entire publication. As I worked for a large publication as the computer age washed over us, I saw it not only cut production time in less than half the time, but the cost savings on production were over half of previous costs.
The personal computer, aside from having the digital age blamed for the slaughter of print, brought about a financial boom for the world. Complain as we might about bidding and crowdsourcing sites, they gave designers throughout the world a chance to compete for work not available in their locale.
It gave small businesses a tool to succeed globally via the internet. Suddenly the world was a possible customer.
Through software, half the administrative chores that bogged down sole proprietors is now automated.
More millionaires are emerging from internet/computer based businesses.
Computers are great for pranking coworkers and destroying the lives of your enemies.
With the number of desktops, laptops, tablets and mobile devices, the world has become connected. We get real news taken on camera phones, meet people in different countries and different cultures on Facebook, Skype and foreign bride sites. Every day the world gets a bit smaller while we learn more and more about each other. That’s a positive thing!

Opportunities abound

Need we talk about the market for apps? It’s not just about coding, it’s also about creativity. The idea, the need and the fulfillment are always driven by creative problem solving.
Other creative projects can be produced over the internet as well as marketed and sold. The options for people to be their own boss, control their own carer paths and steer their own futures is a great thing for creatives who can think of self-initiated, commercial projects.

Taking back design

Anyone can pick up a hammer but that doesn’t make them a carpenter. As creative thinkers, we must master the computer as a tool and apply different, better ways of designing with them. Whether it’s scanning objects for textures or elements of design, hand rendering type for a logo, or breaking rules when designing a web site.
Those who know the tool only for mechanical uses, will never measure up to those who know creative design thought, and can artfully apply it through such a cold, lifeless machine.
Design, of course, must evolve on its own. The tools will change but it is the creativity that will always be the foundation of design. For a while it was Photoshop filters that created the WOW! in design but it was those who mastered the filters and used them in different ways that really set the high bar for such design elements. Photoshop and Illustrator tips and tricks continue to amaze those who learn them and that is part of the evolution of design. In the end, however, we need less to learn about how to make the software work and more about how to make design work!

Webzin Infotech

Webzin Infotech

Web Design India, Web Design Company India, Website Design India, SEO Company India, Mobile Website design India, Web Development Company India :: Webzin Infotech

Web Design India, Web Design Company India, Website Design India, SEO Company India, Mobile Website design India, Web Development Company India :: Webzin Infotech

Web Design India, Web Design Company India, Website Design India, SEO Company India, Mobile Website design India, Web Development Company India :: Webzin Infotech

Web Design India, Web Design Company India, Website Design India, SEO Company India, Mobile Website design India, Web Development Company India :: Webzin Infotech