Javascript-форум (https://javascript.ru/forum/)
-   jQuery (https://javascript.ru/forum/jquery/)
-   -   помогите со скриптом jquery (https://javascript.ru/forum/jquery/35743-pomogite-so-skriptom-jquery.html)

hesrun 20.02.2013 21:02

помогите со скриптом jquery
 
http://jsfiddle.net/RwH5x/

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

Заранее спасибо, помогите плизз...:help: :help: :help:

DjDiablo 20.02.2013 21:44

нужен крохотный скрипт
этот скрипт добавляет класс mini
$(function(){

    $('.plashka').click(function(){
        $(this).toggleClass('mini');
    })

})



Рабочий пример
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
Кликни по блоку с текстом.

<div class="plashka">
                        	<h1>Download this app</h1>
                            <p>Visite our facebook
								Why? For the glory of SATANE of course!
								Workers everywhere should have the right to safe and ethical working conditions. They should also have access to educational oppor Visite our facebook
								Why? For the glory of SATANE of course!
								Workers everywhere should have the right to safe and ethical working conditions. They should also have access to educational oppor Visite our facebook
								Why? For the glory of SATANE of course!
								Workers everywhere should have the right to safe and ethical working conditions. They should also have access to educational oppor</p>
</div>


<script>
$(function(){
    $('.plashka').click(function(){
        $(this).toggleClass('mini');
    })
})
</script>

<style>
.plashka {
	width:440px;
	min-height:110px;
	border:1px #ebebeb solid;
	border-radius:10px; 
}

.mini {
	height:100px;
	overflow:hidden;
}

.plashka h1 {
    font-size:30px;
}
.plashka p {
    margin-top:20px;
}
</style>

hesrun 20.02.2013 23:03

ну это немного не то... Щас опишу...

при нажатии на блоке обвертке, должен плавно открыться полностью абзац и после этого примениться класс, который изменил бы вид блока обвертки, а при втором нажатии абзац закрылся и этот класс удалился.
В общем в задумке сделать блок обвертку в виде кнопки. При наведение срабатывает ховер со своими стилями тенями и т.д., при нажатии, происходит появление абзаца а у дива (кнопки), меняются стили...

рони 20.02.2013 23:12

извините что лезу со своим самоваром ))) но может сгодится http://javascript.ru/forum/project/3...jj-stroki.html

hesrun 20.02.2013 23:25

Цитата:

Сообщение от рони (Сообщение 235973)
извините что лезу со своим самоваром ))) но может сгодится http://javascript.ru/forum/project/3...jj-stroki.html

Тоже не то... Раскрывающийся абзац должен тянуть див обвертку

рони 21.02.2013 00:28

hesrun,
Самовар ненужон, могет чайник сгодится ))
<!DOCTYPE HTML>

<html>

<head>
  <title></title>
  <meta charset="utf-8" />
<style>
.plashka {
	width:440px;
	border:1px #ebebeb solid;
	border-radius:10px;
    overflow:hidden;

}

.maxi {

   background-color:#FFCC00;
   border: #00CC00 1px solid

}

.plashka h1 {
    font-size:30px;
}
.plashka p {
    margin-top:20px;
}
</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>

<body>

Кликни по блоку с текстом.

<div class="plashka">
                        	<h1>Download this app</h1>
                            <p>Visite our facebook
								Why? For the glory of SATANE of course!
								Workers everywhere should have the right to safe and ethical working conditions. They should also have access to educational oppor Visite our facebook
								Why? For the glory of SATANE of course!
								Workers everywhere should have the right to safe and ethical working conditions. They should also have access to educational oppor Visite our facebook
								Why? For the glory of SATANE of course!
								Workers everywhere should have the right to safe and ethical working conditions. They should also have access to educational oppor</p>
</div>


<script>
$(function () {
    var n = 1;
    var h = $('.plashka').outerHeight()
    $('.plashka').height(98);
    $('.plashka').click(function () {
        n ^= 1
        n ? $(this).animate({
            height: 98
        }, 1000, function () {
            $(this).toggleClass('maxi')
        }) : $(this).animate({
            height: h
        }, 1000, function () {
            $(this).toggleClass('maxi')
        })

    })
})
</script>



</body>

</html>

hesrun 21.02.2013 00:36

Цитата:

Сообщение от рони (Сообщение 235985)
hesrun,
Самовар ненужон, могет чайник сгодится ))
<!DOCTYPE HTML>

<html>

<head>
  <title></title>
  <meta charset="utf-8" />
<style>
.plashka {
	width:440px;
	min-height:98px;
	border:1px #ebebeb solid;
	border-radius:10px;
    overflow:hidden;
}

.mini {

   background-color:#FFCC00;
}

.plashka h1 {
    font-size:30px;
}
.plashka p {
    margin-top:20px;
}
</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script language="JavaScript" src="http://code.jquery.com/color/jquery.color-2.1.1.js" type="text/javascript"></script>
</head>

<body>

Кликни по блоку с текстом.

<div class="plashka mini">
                        	<h1>Download this app</h1>
                            <p>Visite our facebook
								Why? For the glory of SATANE of course!
								Workers everywhere should have the right to safe and ethical working conditions. They should also have access to educational oppor Visite our facebook
								Why? For the glory of SATANE of course!
								Workers everywhere should have the right to safe and ethical working conditions. They should also have access to educational oppor Visite our facebook
								Why? For the glory of SATANE of course!
								Workers everywhere should have the right to safe and ethical working conditions. They should also have access to educational oppor</p>
</div>


<script>
$(function () {
    var n = 0;
    var h = $('.plashka').outerHeight()

    $('.plashka').click(function () {
        n ^= 1
        n ? $(this).animate({
            height: 98,
            backgroundColor: '#CCFFFF'

        }, 1000, function () {
            $(this).toggleClass('mini')
        }) : $(this).animate({
            height: h,
            backgroundColor: '#FFCC00'
        }, 1000, function () {
            $(this).toggleClass('mini')
        })

    })
})
</script>



</body>

</html>


Вот мне надо такую, только с перламутровыми пуговицами...
А точнее, с анимацией все четко, как и нужно было... Только стили должны подхватытваться из CSS, не прописывая их в скрипте... И изначально, он (див) должен быть уже маленького размера...

рони 21.02.2013 00:56

Цитата:

Сообщение от hesrun
Только стили должны подхватытваться из CSS, не прописывая их в скрипте... И изначально, он (див) должен быть уже маленького размера...

так пропишите в css всё что нужно и уберите из скрипта всё лишнее.сам скрипт готов дело за вами.
Цитата:

Сообщение от hesrun
при нажатии на блоке обвертке, должен плавно открыться полностью абзац и после этого примениться класс, который изменил бы вид блока обвертки, а при втором нажатии абзац закрылся и этот класс удалился.

скрипт именно так и работает.

danik.js 21.02.2013 01:02

Цитата:

Сообщение от hesrun
Раскрывающийся абзац должен тянуть див обвертку

Так там делов то - удалить div.more{position:absolute} из css. ;)

рони 21.02.2013 01:07

hesrun,
смотрите код в 6 посте

hesrun 21.02.2013 11:17

Цитата:

Сообщение от рони (Сообщение 235998)
hesrun,
смотрите код в 6 посте

Там, если я правильно понял тринарный стоит? А как мне его модифицировать, чтоб он изначально был высотой в 98 пикселей, а потом при щелчке растянулся и при обратном щелчке вернулся в в свои 98...?

рони 21.02.2013 11:48

Цитата:

Сообщение от hesrun
Там, если я правильно понял тринарный стоит? А как мне его модифицировать, чтоб он изначально был высотой в 98 пикселей, а потом при щелчке растянулся и при обратном щелчке вернулся в в свои 98...?

а разве это не так в скрипте?

hesrun 21.02.2013 12:24

Цитата:

Сообщение от рони (Сообщение 235998)
hesrun,
смотрите код в 6 посте

Ну подскажите еще как сделать, чтоб при загрузке страницы блок был 98 пикселей?

hesrun 21.02.2013 12:28

ой, простите... Это я запутался в постах... Спасибо большое ребят! Я хотел изначально с помощью тогла при нажатии в первой функции описать добавление класса а затем slidetoggle закрыть вообще абзац но это немного не то... А так как бы стараюсь учиться, но не всегда в голову мою приходят такие мысли... Учить и еще раз учить...

hesrun 21.02.2013 15:22

<div class="plashka">
<span class="nomber_quest">01</span>
<h1>Download this app</h1>
<div class="quest_share">
<p>5</p>
<span>shares</span>
</div>
<div class="slide_text">Visite our facebook
Why? For the glory of SATANE of course!
Workers everywhere should have the right to safe and ethical working conditions. They should also have access to educational oppor Visite our facebook
Why? For the glory of SATANE of course!
Workers everywhere should have the right to safe and ethical working conditions. They should also have access to educational oppor Visite our facebook
Why? For the glory of SATANE of course!
Workers everywhere should have the right to safe and ethical working conditions. They should also have access to educational oppor</div>
</div><!--plashka-->


$(document).ready(function() {
var n = 1;
var h = $('.slide_text').outerHeight() + 10;
$('.slide_text').height(20);
$('.plashka').click(function () {
n ^= 1
n ? $('.slide_text').animate({height: 20}, 1000, function () {$(this).toggleClass('')}) :
$('.slide_text').animate({height: h}, 1000, function () {$(this).toggleClass('')})

})

});


вот переделал от изначального... На сайте таких плашек куча... Нажимая на одной, раскрываются все все абзацы внутри. Как сделать так, чтоб раскрывался только тот абзац, который находится в диве ко которому был произведен клик? Ну и стиль собственно применялся именно к этому диву... В предыдущем скрипте разъезжался див, а нужно чтоб абзац раскрывался и толкал обвертку....

рони 21.02.2013 15:30

Цитата:

Сообщение от hesrun
Как сделать так, чтоб раскрывался только тот абзац, который находится в диве ко которому был произведен клик?

присвоить клики персонально http://api.jquery.com/each/
Пожалуйста, отформатируйте свой код!

Для этого его можно заключить в специальные теги: js/css/html и т.п., например:
[js]
... ваш код...
[/js]


О том, как вставить в сообщение исполняемый javascript и html-код, а также о дополнительных возможностях форматирования - читайте http://javascript.ru/formatting.

hesrun 21.02.2013 15:48

http://jsfiddle.net/jejyK/

Простите, но как с форума это сделать не догадался...
Как сделать по человечески? Чтоб открывался только нужный абзац, this, next не подходит....

рони 21.02.2013 15:55

Цитата:

Сообщение от hesrun
Как сделать по человечески? Чтоб открывался только нужный абзац

прочитайте
Цитата:

Сообщение от рони
присвоить клики персонально http://api.jquery.com/each/


hesrun 21.02.2013 16:05

Цитата:

Сообщение от рони (Сообщение 236120)
прочитайте

http://jsfiddle.net/jejyK/1/
они чередуются четная с нечетной...

Нашел такое решение, и довольно простое...
http://jsfiddle.net/jejyK/2/
использовал find() перелопатил документацию...

Если не сложно, покажите как можно было это сделать c each()

рони 21.02.2013 17:05

hesrun,
<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title> - jsFiddle demo</title>
  <script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"></script>
  <style type='text/css'>
    .plashka {
	position:relative;
	margin:30px 0 0 0;
	padding:10px 10px 20px 50px;
	width:380px;
	min-height:80px;
	border:1px #ebebeb solid;
}
.nomber_quest {
	position:absolute;
	top:26px;
	left:25px;
	font-size:13px;
	color:#bebebe;
}
.plashka h1 {
	font-size:31px;
	color:#000;
	float:left;
}
.quest_share_blue {
	text-align:center;
	float:right;
	width:85px;
	height:87px;
}
.quest_share_blue p {
	margin-top:15px;
	font-size:30px;
	color:#FFF;
}
.quest_share_blue span {
	color:#FFF;
}
.quest_share_grey {
	text-align:center;
	float:right;
	width:85px;
	height:87px;
}
.quest_share_grey p {
	margin-top:15px;
	font-size:30px;
	color:#FFF;
}
.quest_share_grey span {
	color:#FFF;
}
.slide_text {
	clear:left;
	width:290px;
	font-size:14px;
	color:#666666;
	padding:10px 0 0 0;
	overflow:hidden;
	line-height:20px;
}
.plashka_wrap {
	position:relative;
}
.quest_shadow {
	width:440px;
	height:5px;
	position:absolute;
}
.quest_shadow_inside {
	width:440px;
	height:5px;
	position:absolute;
	top:0px;
}
.left_col_quest {
	float:left;
}
.right_col_quest {
	float:right;
}
  </style>



<script type='text/javascript'>

$(document).ready(function(){
	    $('.plashka').each(function () {
        var n = 1;
	    var h = $('.slide_text', this).outerHeight() + 10;
        $(this).click(function() {
				n ^= 1
				n ? $('.slide_text',this).stop().animate({height: 20}, 500, function () {$(this).toggleClass('')}) :
				$('.slide_text', this).stop().animate({height: h}, 500, function () {$(this).toggleClass('')})
			});
	    })
       $('.slide_text').height(20);
});


</script>


</head>
<body>
  <div class="left_col_quest">
                    	<div class="plashka_wrap">
                        <div class="plashka">
                        	<span class="nomber_quest">01</span>
                        	<h1>Download this app</h1>
                            <div class="quest_share_blue">
                            	<p>5</p>
                                <span>shares</span>
                            </div>
                            <div class="slide_text">Visite our facebook
								Why? For the glory of SATANE of course!
								Workers everywhere should have the right to safe and ethical working conditions. They should also have access to educational oppor Visite our facebook
								Why? For the glory of SATANE of course!
								Workers everywhere should have the right to safe and ethical working conditions. They should also have access to educational oppor Visite our facebook
								Why? For the glory of SATANE of course!
								Workers everywhere should have the right to safe and ethical working conditions. They should also have access to educational oppor11</div>
                            </div><!--plashka-->
                            <div class="quest_shadow">
                            </div>
                        </div><!--plashka_wrap-->

                        <div class="plashka_wrap">
                        <div class="plashka">
                        	<span class="nomber_quest">01</span>
                        	<h1>Download this app</h1>
                            <div class="quest_share_blue">
                            	<p>5</p>
                                <span>shares</span>
                            </div>
                            <div class="slide_text">Visite our facebook
								Why? For the glory of SATANE of course!
								Workers everywhere should have the right to safe and ethical working conditions. They should also have access to educational oppor Visite our facebook
								Why? For the glory of SATANE of course!
								Workers everywhere should have the right to safe and ethical working conditions. They should also have access to educational oppor Visite our facebook
								Why? For the glory of SATANE of course!
								Workers everywhere should have the right to safe and ethical working conditions. They should also have access to educational oppor</div>
                            </div><!--plashka-->
                            <div class="quest_shadow">
                            </div>
                        </div><!--plashka_wrap-->
                        <div class="plashka_wrap">
                        <div class="plashka">
                        	<span class="nomber_quest">01</span>
                        	<h1>Download this app</h1>
                            <div class="quest_share_blue">
                            	<p>5</p>
                                <span>shares</span>
                            </div>
                            <div class="slide_text">Visite our facebook
								Why? For the glory of SATANE of course!
								Workers everywhere should have the right to safe and ethical working conditions. They should also have access to educational oppor Visite our facebook
								Why? For the glory of SATANE of course!
								Workers everywhere should have the right to safe and ethical working conditions. They should also have access to educational oppor Visite our facebook
								Why? For the glory of SATANE of course!
								Workers everywhere should have the right to safe and ethical working conditions. They should also have access to educational oppor</div>
                            </div><!--plashka-->
                            <div class="quest_shadow">
                            </div>
                        </div><!--plashka_wrap-->
                    </div><!--left_col-->



                    <div class="right_col_quest">

                    <div class="plashka_wrap">
                        <div class="plashka">
                        	<span class="nomber_quest">01</span>
                        	<h1>Download this app</h1>
                            <div class="quest_share">
                            	<p>5</p>
                                <span>shares</span>
                            </div>
                            <div class="slide_text">Visite our facebook
								Why? For the glory of SATANE of course!
								Workers everywhere should have the right to safe and ethical working conditions. They should also have access to educational oppor Visite our facebook
								Why? For the glory of SATANE of course!
								Workers everywhere should have the right to safe and ethical working conditions. They should also have access to educational oppor Visite our facebook
								Why? For the glory of SATANE of course!
								Workers everywhere should have the right to safe and ethical working conditions. They should also have access to educational oppor</div>
                            </div><!--plashka-->
                            <div class="quest_shadow">
                            </div>
                        </div><!--plashka_wrap-->
                        <div class="plashka_wrap">
                        <div class="plashka">
                        	<span class="nomber_quest">01</span>
                        	<h1>Download this app</h1>
                            <div class="quest_share">
                            	<p>5</p>
                                <span>shares</span>
                            </div>
                            <div class="slide_text">Visite our facebook
								Why? For the glory of SATANE of course!
								Workers everywhere should have the right to safe and ethical working conditions. They should also have access to educational oppor Visite our facebook
								Why? For the glory of SATANE of course!
								Workers everywhere should have the right to safe and ethical working conditions. They should also have access to educational oppor Visite our facebook
								Why? For the glory of SATANE of course!
								Workers everywhere should have the right to safe and ethical working conditions. They should also have access to educational oppor</div>
                            </div><!--plashka-->
                            <div class="quest_shadow">
                            </div>
                        </div><!--plashka_wrap-->
                        <div class="plashka_wrap">
                        <div class="plashka">
                        	<span class="nomber_quest">01</span>
                        	<h1>Download this app</h1>
                            <div class="quest_share">
                            	<p>5</p>
                                <span>shares</span>
                            </div>
                            <div class="slide_text">Visite our facebook
								Why? For the glory of SATANE of course!
								Workers everywhere should have the right to safe and ethical working conditions. They should also have access to educational oppor Visite our facebook
								Why? For the glory of SATANE of course!
								Workers everywhere should have the right to safe and ethical working conditions. They should also have access to educational oppor Visite our facebook
								Why? For the glory of SATANE of course!
								Workers everywhere should have the right to safe and ethical working conditions. They should also have access to educational oppor</div>
                            </div><!--plashka-->
                            <div class="quest_shadow">
                            </div>
                        </div><!--plashka_wrap-->

                    </div><!--right_col-->

</body>


</html>

рони 21.02.2013 17:12

Цитата:

Сообщение от hesrun
использовал find()

у вас два раза кликать надо по следующему если любой предварительно открыть -- одна n на всё - плюс неучитывается высота каждого содержимого.

hesrun 21.02.2013 17:32

сделал симбиоз...
http://jsfiddle.net/jejyK/3/

hesrun 22.02.2013 12:34

Столкнулся вот еще с какой проблемой!
Кликабельный у меня весь блок, и див с текстом тоже, потому что он внутри блока .plashka... Так вот у меня в сворачиваемом блоке кнопки и ссылки, и когда я на них нажимаю блок сворачивается? Как мне отменить анимацию на этих этих элементах???

danik.js 22.02.2013 12:46

Цитата:

Сообщение от hesrun
Как мне отменить анимацию на этих этих элементах

Я даже просто не могу выделить текст - блок сворачивается (
IMHO неудачная реализация...

hesrun 22.02.2013 12:59

Цитата:

Сообщение от danik.js (Сообщение 236350)
Я даже просто не могу выделить текст - блок сворачивается (
IMHO неудачная реализация...

А можно в функции обратного вызова которая в анимации, написать что-то, чтоб при нажатии на блоке который разворачивается не происходили действия...


Помогите тут:
var h = $('.slide_text').outerHeight(true);

в переменную H получить значение высоты блока .slide_text, в этом блоке находятся еще блоки. Как мне получить высоту которая включает все падинги марджины его и его чилдренят?


Часовой пояс GMT +3, время: 13:10.