Thursday, 25 October 2012

How to enable jQuery intellisense in Visual Studio


There are two ways to enable jQuery intellisense  in an external js file.

First Method :

To use the jQuery intellisense in an external javascript file, use the following configuration line on top of your javascript file.

/// <reference path="jquery-1.2.6.js"/>

The Path should take the original path where the jQuery file is placed in your project.


Second Method:

Simply drag-n-drop the jQuery library from Solution Explorer to the opened external JavaScript file.

jQuery Intellisense in Visual Studio (1)


jQuery intellisense in Visual Studio (2)



Scroll to an element smoothly using jQuery

To get a smooth scrolling effect using one line of jQuery.  You can use this small function of jQuery.  It works especially well with click.


<html>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script>
    $(document).ready(function (){
        $("#click").click(function (){       
                $('html, body').animate({
                    scrollTop: $("#div1").offset().top
                     }, 2000);
        });
    });
</script>
<div id="div1" style="height: 1000px; width 100px">
test
</div>
<br/>
<div id="div2" style="height: 1000px; width 100px">
test 2
</div>
<button id="click">click me</button>
</html>