简体   繁体   中英

How to include a jquery plugin in your code

This may be a really dumb question but I'm having trouble including a jquery plugin in my code. The plugin I'm referring to is: http://davidlynch.org/projects/maphilight/docs/

I want to mimic something very similar to the following: http://jsfiddle.net/keith/PVpgK/

But when I copy the code over, I keep getting error messages saying "maphilight is not a function"

How do I use a jquery plugin in my code? Thank you

$(function() {
   //using the jquery map highlight plugin:
   //http://davidlynch.org/js/maphilight/docs/

   //initialize highlight
   $('.map').maphilight({strokeColor:'808080',strokeWidth:0,fillColor:'00cd27'});


   //hover effect
   $('#maplink1').mouseover(function(e) {
      $('#map1').mouseover();
   }).mouseout(function(e) {
      $('#map1').mouseout();
   }).click(function(e) { e.preventDefault(); });


   // initialize tabbing
   $(".tabs area:eq(0)").each(function(){
       $(this).addClass("current");
   });
   $(".tab-content").each(function(){
       $(this).children(":not(:first)").hide();    
   });


   //map clicks
   $(".tabs area").click(function(){

   //This block is what creates highlighting by trigger the "alwaysOn", 
   var data = $(this).data('maphilight') || {};
   data.alwaysOn = !data.alwaysOn;
   $(this).data('maphilight', data).trigger('alwaysOn.maphilight');
   //there is also "neverOn" in the docs, but not sure how to get it to work


   if ($(this).hasClass("current") == false)
   {
       var thisTarget = $(this).attr("href");

       $(this).parents(".tabs").find('area.current').removeClass('current');

       $(this).addClass('current');

       $(this).parents(".tabs").nextAll(".tab-content").children(":visible").fadeOut(1, function() {
           $(thisTarget).fadeIn("fast");
       });

   }
   return false; 
  });
});

You need to include the link to jquery in your html header.

1) Download jquery from jQuery.com

2) Link to downloaded file in your header

Like so:

<head>
     ...
     <script src="/path/to/jquery-1.11.3.min.js"></script>
     ...
</head>

As the previous answer. But put them in the bottom of the body tag.

 <html>
   <head>

   </head>
   <body>

      <script src="../path/to/jquery-1.11.3.min.js"></script>
      <script src="http://davidlynch.org/js/maphilight/jquery.maphilight.min.js"></script>
   </body>
  </html>

you need to add the following to the header of your html code

<script type="text/javascript" src="http://davidlynch.org/js/maphilight/jquery.maphilight.min.js">
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM