View previous topic :: View next topic
Author
Message
Zeus Joined: 09 Sep 2003 Posts: 775 Location: Čakovec
Posted: 26.10.2008 12:28 Post subject: Javascript random
Da li moze netko 'preobratit' ovaj kod da se desava random, ovo je iz modula (iz joomle) koji radi izmjenu slikica po redu (od prve prema zadnjoj), a meni treba random. Da li se to uopce tu moze odrediti?
Code: var is_ie/*@cc_on = {
// quirksmode : (document.compatMode=="BackCompat"),
version : parseFloat(navigator.appVersion.match(/MSIE (.+?);/)[1])
}@*/;
function opacity(id, opacStart, opacEnd, millisec) {
//speed for each frame
var speed = Math.round(millisec / 100);
var timer = 0;
//determine the direction for the blending, if start and end are the same nothing happens
if(opacStart > opacEnd) {
for(i = opacStart; i >= opacEnd; i--) {
setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
timer++;
}
} else if(opacStart < opacEnd) {
for(i = opacStart; i <= opacEnd; i++)
{
setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
timer++;
}
}
}
//change the opacity for different browsers
function changeOpac(opacity, id) {
var object = document.getElementById(id).style;
object.opacity = (opacity / 100);
object.MozOpacity = (opacity / 100);
object.KhtmlOpacity = (opacity / 100);
object.filter = "alpha(opacity=" + opacity + ")";
}
function blendimage(divid, imageid, imagefile, millisec) {
var speed = Math.round(millisec / 100);
var timer = 0;
//set the current image as background
document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
//make image transparent
changeOpac(0, imageid);
//make new image
document.getElementById(imageid).src = imagefile;
//fade in image
for(i = 0; i <= 100; i++) {
setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
timer++;
}
}
function currentOpac(id, opacEnd, millisec) {
//standard opacity is 100
var currentOpac = 100;
//if the element has an opacity set, get it
if(document.getElementById(id).style.opacity < 100) {
currentOpac = document.getElementById(id).style.opacity * 100;
}
//call for the function that changes the opacity
opacity(id, currentOpac, opacEnd, millisec)
}
Back to top
PaNtHeR Joined: 17 Sep 2003 Posts: 161
Posted: 26.10.2008 13:00 Post subject:
A kako izgleda div ili šta već u kojem mu kažeš koje slike da rotira? Pomoglo bi kad bi i to vidjeli.
Možda da napraviš taj random dio u PHP-u, odnosno da svaki puta drugim redoslijedom "ispljuneš" slike iz baze.
_________________•
Back to top
Zeus Joined: 09 Sep 2003 Posts: 775 Location: Čakovec
Posted: 26.10.2008 13:04 Post subject:
Code: <?php
/**
@version 1.0: mod_S5_imagefader
Author: Shape 5 - Professional Template Community
Available for download at www.shape5.com
*/
// no direct access
defined( '_VALID_MOS' ) or die( 'Restricted access' );
$background = $params->get( 'background', '' );
$pretext = $params->get( 'pretext', '' );
$tween_time = $params->get( 'tween_time', '' );
$height = $params->get( 'height', '' );
$width = $params->get( 'width', '' );
$picture1 = $params->get( 'picture1', '' );
$picture1link = $params->get( 'picture1link', '' );
$picture1target = $params->get( 'picture1target', '' );
$picture2 = $params->get( 'picture2', '' );
$picture2link = $params->get( 'picture2link', '' );
$picture2target = $params->get( 'picture2target', '' );
$picture3 = $params->get( 'picture3', '' );
$picture3link = $params->get( 'picture3link', '' );
$picture3target = $params->get( 'picture3target', '' );
$picture4 = $params->get( 'picture4', '' );
$picture4link = $params->get( 'picture4link', '' );
$picture4target = $params->get( 'picture4target', '' );
$picture5 = $params->get( 'picture5', '' );
$picture5link = $params->get( 'picture5link', '' );
$picture5target = $params->get( 'picture5target', '' );
$picture6 = $params->get( 'picture6', '' );
$picture6link = $params->get( 'picture6link', '' );
$picture6target = $params->get( 'picture6target', '' );
$picture7 = $params->get( 'picture7', '' );
$picture7link = $params->get( 'picture7link', '' );
$picture7target = $params->get( 'picture7target', '' );
$picture8 = $params->get( 'picture8', '' );
$picture8link = $params->get( 'picture8link', '' );
$picture8target = $params->get( 'picture8target', '' );
$picture9 = $params->get( 'picture9', '' );
$picture9link = $params->get( 'picture9link', '' );
$picture9target = $params->get( 'picture9target', '' );
$picture10 = $params->get( 'picture10', '' );
$picture10link = $params->get( 'picture10link', '' );
$picture10target = $params->get( 'picture10target', '' );
$display_time = $params->get( 'display_time', '' );
$tween_time = $tween_time*1000;
$display_time = $display_time*1000;
if ($picture1target == "1") {
$picture1target = "_blank"; }
if ($picture1target == "0") {
$picture1target = "_top"; }
if ($picture2target == "1") {
$picture2target = "_blank"; }
if ($picture2target == "0") {
$picture2target = "_top"; }
if ($picture3target == "1") {
$picture3target = "_blank"; }
if ($picture3target == "0") {
$picture3target = "_top"; }
if ($picture4target == "1") {
$picture4target = "_blank"; }
if ($picture4target == "0") {
$picture4target = "_top"; }
if ($picture5target == "1") {
$picture5target = "_blank"; }
if ($picture5target == "0") {
$picture5target = "_top"; }
if ($picture6target == "1") {
$picture6target = "_blank"; }
if ($picture6target == "0") {
$picture6target = "_top"; }
if ($picture7target == "1") {
$picture7target = "_blank"; }
if ($picture7target == "0") {
$picture7target = "_top"; }
if ($picture8target == "1") {
$picture8target = "_blank"; }
if ($picture8target == "0") {
$picture8target = "_top"; }
if ($picture9target == "1") {
$picture9target = "_blank"; }
if ($picture9target == "0") {
$picture9target = "_top"; }
if ($picture10target == "1") {
$picture10target = "_blank"; }
if ($picture10target == "0") {
$picture10target = "_top"; }
?>
<?php if ($pretext != "") { ?>
<br />
<?php echo $pretext ?>
<br /><br />
<?php } ?>
<?php
$br = strtolower($_SERVER['HTTP_USER_AGENT']); // what browser.
if(ereg("msie 6", $br)) {
$iss_ie6 = "yes";
}
else {
$iss_ie6 = "no";
}
?>
<?php
$br = strtolower($_SERVER['HTTP_USER_AGENT']); // what browser.
if(ereg("msie 7", $br)) {
$iss_ie7 = "yes";
}
else {
$iss_ie7 = "no";
}
?>
<div style="height:<?php echo $height ?>; width:<?php echo $width ?>; overflow:hidden; background:#<?php echo $background ?>">
<?php if ($picture1 != "") { ?>
<div id="picture1" style="padding:0px; display:none; height:<?php echo $height ?>; opacity:.0; <?php if ($iss_ie6 == "yes") { ?>filter: alpha(opacity=0); -moz-opacity: 0;<?php } ?> width:<?php echo $width ?>; overflow:hidden; background-image: url(<?php echo $picture1 ?>); background-repeat: no-repeat"><?php if ($picture1link != "") { ?><a href="<?php echo $picture1link ?>" target="<?php echo $picture1target ?>"><img alt="" style="border:none" src="<?php echo $mosConfig_live_site;?>/modules/s5_imagefader/blank.gif" height="<?php echo $height ?>" width="<?php echo $width ?>"></img></a><?php } ?></div>
<?php } ?>
<?php if ($picture2 != "") { ?>
<div id="picture2" style="padding:0px; display:none; height:<?php echo $height ?>; opacity:.0; <?php if ($iss_ie6 == "yes") { ?>filter: alpha(opacity=0); -moz-opacity: 0;<?php } ?> width:<?php echo $width ?>; overflow:hidden; background-image: url(<?php echo $picture2 ?>); background-repeat: no-repeat"><?php if ($picture2link != "") { ?><a href="<?php echo $picture2link ?>" target="<?php echo $picture2target ?>"><img alt="" style="border:none" src="<?php echo $mosConfig_live_site;?>/modules/s5_imagefader/blank.gif" height="<?php echo $height ?>" width="<?php echo $width ?>"></img></a><?php } ?></div>
<?php } ?>
<?php if ($picture3 != "") { ?>
<div id="picture3" style="padding:0px; display:none; height:<?php echo $height ?>; opacity:.0; <?php if ($iss_ie6 == "yes") { ?>filter: alpha(opacity=0); -moz-opacity: 0;<?php } ?> width:<?php echo $width ?>; overflow:hidden; background-image: url(<?php echo $picture3 ?>); background-repeat: no-repeat"><?php if ($picture3link != "") { ?><a href="<?php echo $picture3link ?>" target="<?php echo $picture3target ?>"><img alt="" style="border:none" src="<?php echo $mosConfig_live_site;?>/modules/s5_imagefader/blank.gif" height="<?php echo $height ?>" width="<?php echo $width ?>"></img></a><?php } ?></div>
<?php } ?>
<?php if ($picture4 != "") { ?>
<div id="picture4" style="padding:0px; display:none; height:<?php echo $height ?>; opacity:.0; <?php if ($iss_ie6 == "yes") { ?>filter: alpha(opacity=0); -moz-opacity: 0;<?php } ?> width:<?php echo $width ?>; overflow:hidden; background-image: url(<?php echo $picture4 ?>); background-repeat: no-repeat"><?php if ($picture4link != "") { ?><a href="<?php echo $picture4link ?>" target="<?php echo $picture4target ?>"><img alt="" style="border:none" src="<?php echo $mosConfig_live_site;?>/modules/s5_imagefader/blank.gif" height="<?php echo $height ?>" width="<?php echo $width ?>"></img></a><?php } ?></div>
<?php } ?>
<?php if ($picture5 != "") { ?>
<div id="picture5" style="padding:0px; display:none; height:<?php echo $height ?>; opacity:.0; <?php if ($iss_ie6 == "yes") { ?>filter: alpha(opacity=0); -moz-opacity: 0;<?php } ?> width:<?php echo $width ?>; overflow:hidden; background-image: url(<?php echo $picture5 ?>); background-repeat: no-repeat"><?php if ($picture5link != "") { ?><a href="<?php echo $picture5link ?>" target="<?php echo $picture5target ?>"><img alt="" style="border:none" src="<?php echo $mosConfig_live_site;?>/modules/s5_imagefader/blank.gif" height="<?php echo $height ?>" width="<?php echo $width ?>"></img></a><?php } ?></div>
<?php } ?>
<?php if ($picture6 != "") { ?>
<div id="picture6" style="padding:0px; display:none; height:<?php echo $height ?>; opacity:.0; <?php if ($iss_ie6 == "yes") { ?>filter: alpha(opacity=0); -moz-opacity: 0;<?php } ?> width:<?php echo $width ?>; overflow:hidden; background-image: url(<?php echo $picture6 ?>); background-repeat: no-repeat"><?php if ($picture6link != "") { ?><a href="<?php echo $picture6link ?>" target="<?php echo $picture6target ?>"><img alt="" style="border:none" src="<?php echo $mosConfig_live_site;?>/modules/s5_imagefader/blank.gif" height="<?php echo $height ?>" width="<?php echo $width ?>"></img></a><?php } ?></div>
<?php } ?>
<?php if ($picture7 != "") { ?>
<div id="picture7" style="padding:0px; display:none; height:<?php echo $height ?>; opacity:.0; <?php if ($iss_ie6 == "yes") { ?>filter: alpha(opacity=0); -moz-opacity: 0;<?php } ?> width:<?php echo $width ?>; overflow:hidden; background-image: url(<?php echo $picture7 ?>); background-repeat: no-repeat"><?php if ($picture7link != "") { ?><a href="<?php echo $picture7link ?>" target="<?php echo $picture7target ?>"><img alt="" style="border:none" src="<?php echo $mosConfig_live_site;?>/modules/s5_imagefader/blank.gif" height="<?php echo $height ?>" width="<?php echo $width ?>"></img></a><?php } ?></div>
<?php } ?>
<?php if ($picture8 != "") { ?>
<div id="picture8" style="padding:0px; display:none; height:<?php echo $height ?>; opacity:.0; <?php if ($iss_ie6 == "yes") { ?>filter: alpha(opacity=0); -moz-opacity: 0;<?php } ?> width:<?php echo $width ?>; overflow:hidden; background-image: url(<?php echo $picture8 ?>); background-repeat: no-repeat"><?php if ($picture8link != "") { ?><a href="<?php echo $picture8link ?>" target="<?php echo $picture8target ?>"><img alt="" style="border:none" src="<?php echo $mosConfig_live_site;?>/modules/s5_imagefader/blank.gif" height="<?php echo $height ?>" width="<?php echo $width ?>"></img></a><?php } ?></div>
<?php } ?>
<?php if ($picture9 != "") { ?>
<div id="picture9" style="padding:0px; display:none; height:<?php echo $height ?>; opacity:.0; <?php if ($iss_ie6 == "yes") { ?>filter: alpha(opacity=0); -moz-opacity: 0;<?php } ?> width:<?php echo $width ?>; overflow:hidden; background-image: url(<?php echo $picture9 ?>); background-repeat: no-repeat"><?php if ($picture9link != "") { ?><a href="<?php echo $picture9link ?>" target="<?php echo $picture9target ?>"><img alt="" style="border:none" src="<?php echo $mosConfig_live_site;?>/modules/s5_imagefader/blank.gif" height="<?php echo $height ?>" width="<?php echo $width ?>"></img></a><?php } ?></div>
<?php } ?>
<?php if ($picture10 != "") { ?>
<div id="picture10" style="padding:0px; display:none; height:<?php echo $height ?>; opacity:.0; <?php if ($iss_ie6 == "yes") { ?>filter: alpha(opacity=0); -moz-opacity: 0;<?php } ?> width:<?php echo $width ?>; overflow:hidden; background-image: url(<?php echo $picture10 ?>); background-repeat: no-repeat"><?php if ($picture10link != "") { ?><a href="<?php echo $picture10link ?>" target="<?php echo $picture10target ?>"><img alt="" style="border:none" src="<?php echo $mosConfig_live_site;?>/modules/s5_imagefader/blank.gif" height="<?php echo $height ?>" width="<?php echo $width ?>"></img></a><?php } ?></div>
<?php } ?>
</div>
<script language="javascript" type="text/javascript" src="<?php echo $mosConfig_live_site;?>/modules/s5_imagefader/fader.js"></script>
<script type="text/javascript">
function picture1(id) {
document.getElementById(id).style.display = "block";
opacity(id, 0, 100, <?php echo $tween_time ?>);
window.setTimeout('picture1_done()',<?php echo $display_time ?>);
}
function picture1_done(){
picture1_doneload('picture1');
}
function picture1_doneload(id) {
opacity(id, 100, 0, <?php echo $tween_time ?>);
window.setTimeout('picture1_next()',<?php echo $tween_time ?>);
}
function picture1_next(id) {
document.getElementById('picture1').style.display = "none";
if (document.getElementById('picture2')) {
picture2('picture2');
}
else {
picture1('picture1');
}
}
function picture2(id) {
document.getElementById(id).style.display = "block";
opacity(id, 0, 100, <?php echo $tween_time ?>);
window.setTimeout('picture2_done()',<?php echo $display_time ?>);
}
function picture2_done(){
picture2_doneload('picture2');
}
function picture2_doneload(id) {
opacity(id, 100, 0, <?php echo $tween_time ?>);
window.setTimeout('picture2_next()',<?php echo $tween_time ?>);
}
function picture2_next(id) {
document.getElementById('picture2').style.display = "none";
if (document.getElementById('picture3')) {
picture3('picture3');
}
else {
picture1('picture1');
}
}
function picture3(id) {
document.getElementById(id).style.display = "block";
opacity(id, 0, 100, <?php echo $tween_time ?>);
window.setTimeout('picture3_done()',<?php echo $display_time ?>);
}
function picture3_done(){
picture3_doneload('picture3');
}
function picture3_doneload(id) {
opacity(id, 100, 0, <?php echo $tween_time ?>);
window.setTimeout('picture3_next()',<?php echo $tween_time ?>);
}
function picture3_next(id) {
document.getElementById('picture3').style.display = "none";
if (document.getElementById('picture4')) {
picture4('picture4');
}
else {
picture1('picture1');
}
}
function picture4(id) {
document.getElementById(id).style.display = "block";
opacity(id, 0, 100, <?php echo $tween_time ?>);
window.setTimeout('picture4_done()',<?php echo $display_time ?>);
}
function picture4_done(){
picture4_doneload('picture4');
}
function picture4_doneload(id) {
opacity(id, 100, 0, <?php echo $tween_time ?>);
window.setTimeout('picture4_next()',<?php echo $tween_time ?>);
}
function picture4_next(id) {
document.getElementById('picture4').style.display = "none";
if (document.getElementById('picture5')) {
picture5('picture5');
}
else {
picture1('picture1');
}
}
function picture5(id) {
document.getElementById(id).style.display = "block";
opacity(id, 0, 100, <?php echo $tween_time ?>);
window.setTimeout('picture5_done()',<?php echo $display_time ?>);
}
function picture5_done(){
picture5_doneload('picture5');
}
function picture5_doneload(id) {
opacity(id, 100, 0, <?php echo $tween_time ?>);
window.setTimeout('picture5_next()',<?php echo $tween_time ?>);
}
function picture5_next(id) {
document.getElementById('picture5').style.display = "none";
if (document.getElementById('picture6')) {
picture6('picture6');
}
else {
picture1('picture1');
}
}
function picture6(id) {
document.getElementById(id).style.display = "block";
opacity(id, 0, 100, <?php echo $tween_time ?>);
window.setTimeout('picture6_done()',<?php echo $display_time ?>);
}
function picture6_done(){
picture6_doneload('picture6');
}
function picture6_doneload(id) {
opacity(id, 100, 0, <?php echo $tween_time ?>);
window.setTimeout('picture6_next()',<?php echo $tween_time ?>);
}
function picture6_next(id) {
document.getElementById('picture6').style.display = "none";
if (document.getElementById('picture7')) {
picture7('picture7');
}
else {
picture1('picture1');
}
}
function picture7(id) {
document.getElementById(id).style.display = "block";
opacity(id, 0, 100, <?php echo $tween_time ?>);
window.setTimeout('picture7_done()',<?php echo $display_time ?>);
}
function picture7_done(){
picture7_doneload('picture7');
}
function picture7_doneload(id) {
opacity(id, 100, 0, <?php echo $tween_time ?>);
window.setTimeout('picture7_next()',<?php echo $tween_time ?>);
}
function picture7_next(id) {
document.getElementById('picture7').style.display = "none";
if (document.getElementById('picture8')) {
picture8('picture8');
}
else {
picture1('picture1');
}
}
function picture8(id) {
document.getElementById(id).style.display = "block";
opacity(id, 0, 100, <?php echo $tween_time ?>);
window.setTimeout('picture8_done()',<?php echo $display_time ?>);
}
function picture8_done(){
picture8_doneload('picture8');
}
function picture8_doneload(id) {
opacity(id, 100, 0, <?php echo $tween_time ?>);
window.setTimeout('picture8_next()',<?php echo $tween_time ?>);
}
function picture8_next(id) {
document.getElementById('picture8').style.display = "none";
if (document.getElementById('picture9')) {
picture9('picture9');
}
else {
picture1('picture1');
}
}
function picture9(id) {
document.getElementById(id).style.display = "block";
opacity(id, 0, 100, <?php echo $tween_time ?>);
window.setTimeout('picture9_done()',<?php echo $display_time ?>);
}
function picture9_done(){
picture9_doneload('picture9');
}
function picture9_doneload(id) {
opacity(id, 100, 0, <?php echo $tween_time ?>);
window.setTimeout('picture9_next()',<?php echo $tween_time ?>);
}
function picture9_next(id) {
document.getElementById('picture9').style.display = "none";
if (document.getElementById('picture10')) {
picture10('picture10');
}
else {
picture1('picture1');
}
}
function picture10(id) {
document.getElementById(id).style.display = "block";
opacity(id, 0, 100, <?php echo $tween_time ?>);
window.setTimeout('picture10_done()',<?php echo $display_time ?>);
}
function picture10_done(){
picture10_doneload('picture10');
}
function picture10_doneload(id) {
opacity(id, 100, 0, <?php echo $tween_time ?>);
window.setTimeout('picture10_next()',<?php echo $tween_time ?>);
}
function picture10_next(id) {
document.getElementById('picture10').style.display = "none";
picture1('picture1');
}
picture1('picture1');
</script>
Back to top
PaNtHeR Joined: 17 Sep 2003 Posts: 161
Posted: 26.10.2008 13:11 Post subject:
a u k... odustajem
Sorry ali ja tu ništa ne kužim
Ja bi tu napravio random dio u php-u, odnosno napunio varijable $picture1-$picture10 svaki puta random vrijednostima.
P.S. Šta nije to malo prekomplicirani image rotator? Last edited by PaNtHeR on 26.10.2008 13:22; edited 1 time in total
_________________•
Back to top
Zeus Joined: 09 Sep 2003 Posts: 775 Location: Čakovec
Posted: 26.10.2008 13:22 Post subject:
To je jedini koji sam nasao za joomlu kakav mi treba (rotira zadane slike, a svaka slika ima svoj link).
Back to top
ghosap Joined: 18 Sep 2003 Posts: 79
Posted: 26.10.2008 16:32 Post subject:
Oprosti ako ispadne bezobrazan al jesi ikad čuo da za petlje ?! Ova tvoja galaksija koda može u 10% svoje veličine, prvo to sredi pa će onda netko možda i bit voljan to pogledat ...
_________________ . . . and when the balance is lost all that is left is the reckening . . .
Back to top
base Joined: 12 Jul 2007 Posts: 96
Posted: 26.10.2008 23:09 Post subject:
LOL, ovaj "code" div je visok oko 2 i po metra.
Back to top
Zeus Joined: 09 Sep 2003 Posts: 775 Location: Čakovec
Posted: 26.10.2008 23:29 Post subject:
Niti sam ovo programirao, niti želim oću samo random ovoga, tako da ako nemate nešto pametno, stfu
Back to top
PaNtHeR Joined: 17 Sep 2003 Posts: 161
Posted: 27.10.2008 11:08 Post subject:
Gle ovaj kod je fundamentalno krivo složen, i sam po sebi ide u sekvenci od 1 do 10, i mislim da ako želiš random moraš dosta toga promijenit. Rekao sam ti da putem php-a napuniš varijeble $picture1-$picture10 s random vrijednostima.
edit:
treba ti bit ovako:
Code:
...
$picture10 = $params->get( 'picture10', '' );
$picture10link = $params->get( 'picture10link', '' );
$picture10target = $params->get( 'picture10target', '' );
$display_time = $params->get( 'display_time', '' );
//ovaj dio ubacujes
$i = 1;
while (1) {
$varname = "picture".$i;
if ($$varname) {
$slike[] = $$varname;
$i++;
} else {
break;
}
}
shuffle($slike);
$i = 1;
foreach ($slike as $slika) {
$varname = "picture".$i;
$$varname = $slika;
$i++;
}
////////////////////////////////////////////////////////////
$tween_time = $tween_time*1000;
$display_time = $display_time*1000;
if ($picture1target == "1") {
$picture1target = "_blank"; }
if ($picture1target == "0") {
$picture1target = "_top"; }
if ($picture2target == "1") {
$picture2target = "_blank"; }
...
Last edited by PaNtHeR on 27.10.2008 11:28; edited 3 times in total
_________________•
Back to top
Zeus Joined: 09 Sep 2003 Posts: 775 Location: Čakovec
Posted: 27.10.2008 11:13 Post subject:
Hvala, pokusat cu nesto s ovim...
Back to top
base Joined: 12 Jul 2007 Posts: 96
Posted: 27.10.2008 11:22 Post subject:
Zeus wrote: Niti sam ovo programirao, niti želim oću samo random ovoga, tako da ako nemate nešto pametno, stfu
sori al' bilo mi je smiješno
Back to top
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
Powered by phpBB © 2001, 2005 phpBB Group