использование JQuery и Prototype на одной странице; нужно больше объяснений! - PullRequest
2 голосов
/ 03 апреля 2010

У меня постоянно возникают проблемы, когда я использую лайтбокс jquery (запускающий прототип) и слайдер новостей jquery.

Я попробовал метод "noconflict".

Проблема в том, что я не знаю точное место для кода.

Итак, я помещаю свои сценарии внутрь.

Итак, пожалуйста, устраните неполадки и объясните мне, куда поставить патч.

Большое спасибо.

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<title>Jquery</title> 

<script type="text/javascript" src="lb/js/prototype.js"></script>
<script type="text/javascript" src="lb/js/scriptaculous.js?load=effects"></script>
<script type="text/javascript" src="lb/js/lightbox.js"></script>
<link href="lb/css/lightbox.css" rel="stylesheet" type="text/css" />

<script type="text/javascript" src="news/jquery-1.2.3.pack.js"></script>
<script type="text/javascript" src="news/jquery.easynews.js"></script>



<style>
html
{ background-color: #FFA928;
font: normal 76% "Arial", "Lucida Grande",Verdana,  Sans-Serif;
 color:black;
 }
a { text-decoration: none; font-weight: bold; }

.news_style{
display:none;
}
.news_show
{
background-color: white;
color:black;
width:350px;
height:150px;
font: normal 100% "Arial", "Lucida Grande",Verdana,  Sans-Serif;
overflow: auto; 

}
.news_border
{
background-color: white;
width:350px;
height:150px;
font: normal 100% "Arial", "Lucida Grande",Verdana,  Sans-Serif;
border: 1px solid gray;
padding: 5px 5px 5px 5px;
overflow: auto; 

}
.news_mark{
background-color:white ;
font: normal 70% "Arial", "Lucida Grande",Verdana,  Sans-Serif;
border: 0px solid gray;
width:361px;
height:35px;
color:black;
text-align:center;
}
.news_title{
font: bold 120% "Arial", "Lucida Grande",Verdana,  Sans-Serif;
border: 0px solid gray;
padding: 5px 0px 9px 5px;
color:black;
}
.news_show img{

margin-left: 5px;
margin-right: 5px;

}
.buttondiv
{
position: absolute;
/*float: left;*/
/*top: 169px;*/
padding: 5px 5px 5px 5px;
background-color:white ;
border: 1px solid gray;
/*border-top-color: white;*/
border-top:none;
height:20px;
}

</style>
<script>
$(document).ready(function(){
var newsoption1 = {
  firstname: "mynews",
  secondname: "showhere",
  thirdname:"news_display",
  fourthname:"news_button",
   newsspeed:'6000'
}
$.init_news(newsoption1);


var myoffset=$('#news_button').offset();

var mytop=myoffset.top-1;

$('#news_button').css({top:mytop});

});
</script>

</head>

Ответы [ 3 ]

3 голосов
/ 03 апреля 2010

Я не знаю, насколько яснее вы можете получить объяснение здесь

По сути, вызов jQuery.noConflict возвращает переменную $ к тому, что было определено до загрузки jQuery.

После этого вам нужно вызвать jQuery, чтобы использовать его напрямую. В моем случае я переопределяю это так:

$j = jQuery; // Now I can use $j for jQuery and $ for Prototype

Вы также можете использовать $ внутри функции готовности, например:

jQuery(document).ready(function($) {
  // Code that uses jQuery's $ can follow here.
});

Довольно просто ... что вас смущает?

0 голосов
/ 03 апреля 2010

Положите вызов $ .noConflict () сразу после включения библиотеки jquery. Смотрите здесь .

<script type="text/javascript" src="news/jquery-1.2.3.pack.js"></script>
<script type="text/javascript">
  $.noConflict();
  // Code that uses other library's $ can follow here.
</script>
0 голосов
/ 03 апреля 2010

А? лайтбокс jQuery не использует прототип. Что именно вы используете?

Попробуйте это http://leandrovieira.com/projects/jquery/lightbox/

И, если можете, сбросьте все прототипы вместе. Лучше избегать двух громоздких рамок.

...