1. Using Style.
This is Style code
- <style>
- img{
- width:30%;
- }
- img:hover{
- transition-property:width;
- transition-duration:1s;
- width:50%;
- }
- </style>
" img:hover{} " means mouse pointer's on the img.
"transition-property" means event property. so width is change.
"transition-duration" means event time.
This is initial status.
This is mouse hover status.
2. Using JavaScrpit & class
You need a JavaScript code
- <script type="text/javascript">
- $(document).ready(function() {
- $("#pic").click(function(){
- if($(this).hasClass("small")){
- $("#pic").addClass("large") ;
- $("#pic").removeClass("small") ;
- }
- else{
- $("#pic").addClass("small") ;
- $("#pic").removeClass("large") ;
- }
- });
- });
- </script>
"$(this).hasClass("class")" check class. If it has a class that return true. else false.
So. If #pic has a small class, add large class and remove small class.
This is style code
- <style>
- #pic{
- -webkit-transition-property:width;
- -webkit-transition-duration:1s;
- }
- .small{
- width: 30%;
- }
- .large{
- width:50%;
- }
- </style>
This is image code
- <img class="small" id="pic"src="http://images.forbes.com/media/lists/companies/google_200x200.jpg"/>
This is before click
This is after click.
No comments:
Post a Comment