Конфликт: при загрузке дочерней страницы JavaScript не работает - PullRequest
0 голосов
/ 14 февраля 2012

Я пытаюсь интегрировать это конкретное приложение в мой сайт.

Когда я загружаю его как контент на мою главную страницу, мое меню jquery с главной страницы перестает работать. Кажется, здесь есть конфликт. Вот скрипт с дочерней страницы:

<script type='text/javascript'>
  $(function() {
    var bucharest = new google.maps.LatLng(44.436055, 26.097593),
      pointToMoveTo, 
      first = true,
      curMarker = new google.maps.Marker({}),
      $el;

  var myOptions = {
      zoom: 13,
      center: bucharest,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };

  var map = new google.maps.Map($("#map_canvas")[0], myOptions);

  $("#locations li").mouseenter(function() {

    $el = $(this);

    if (!$el.hasClass("hover")) {

      $("#locations li").removeClass("hover");
      $el.addClass("hover");

      if (!first) { 

        // Clear current marker
        curMarker.setMap(); 

        // Set zoom back to Bucharest level
        // map.setZoom(10);
      }

      // Move (pan) map to new location
      pointToMoveTo = new google.maps.LatLng($el.attr("data-geo-lat"), $el.attr("data-geo-long"));
      map.panTo(pointToMoveTo);

      // Add new marker
      curMarker = new google.maps.Marker({
          position: pointToMoveTo,
          map: map,
          icon: "images/marker.png"
      });

      // On click, zoom map
      google.maps.event.addListener(curMarker, 'click', function() {
         map.setZoom(14);
      });

      // Fill more info area
      $("#more-info")
        .find("h2")
          .html($el.find("h3").html())
          .end()
        .find("p")
          .html($el.find(".longdesc").html());

      // No longer the first time through (re: marker clearing)        
      first = false; 
    }

  });

  $("#locations li:first").trigger("mouseenter");

});

Вот скрипт для меню на главной странице:

$(document).ready(function() {
    $("ul#nav li a").addClass("js");
    $("ul#nav li a").hover(
      function () {
        $(this).stop(true,true).animate({backgroundPosition:"(0 0)"}, 200);
        $(this).animate({backgroundPosition:"(0 -5px)"}, 150);
      },
      function () {
        $(this).animate({backgroundPosition:"(0 -149px)"}, 200);

      }
    );

});

Есть ли конфликт между этими двумя? Спасибо!

1 Ответ

1 голос
/ 14 февраля 2012

Я думаю, что в вашем первом документе есть ошибка.

here : $(function() {

Итак, второй документ. Уже

this one : $(document).ready(function() {
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...