I'm setting up a horizontally scrolling site, with Index Exhibit. One section needs to have a video, which I can't set up in the Indexhibit CMS backend (where it would add it to the wide div's width), so I need to add it to the PHP generation file. Basically, it needs to check if an element with the ID vid
is present. If so, it should add the vid_width
and vid_right_padding
to the final width, final_img_container
. If not, it should be left out. The website with the video can be found here: http://www.allisonnavon.com/index.php?/projects/the-alka-seltzer-challenge/ As you can see here, the width is perfect, but when other pages are loaded, there is a huge 800 extra pixels on the right end of each project.
Here is the code:
<?php if (!defined('SITE')) exit('No direct script access allowed');
/**
* Horizontal Format
*
* Exhbition format
* Originally created for SharoneLifschitz.com
*
* @version 1.1
* @author Vaska
*/
$DO = new Horizontally;
$exhibit['exhibit'] = $DO->createExhibit();
$exhibit['dyn_css'] = $DO->dynamicCSS();
class Horizontally
{
// PADDING AND TEXT WIDTH ADJUSTMENTS UP HERE!!!
var $picture_block_padding_right = 25;
var $text_width = 250;
var $text_padding_right = 75;
var $vid_width = 800;
var $vid_padding_right = 25;
var $final_img_container = 0; // do not adjust this one
function createExhibit()
{
$OBJ =& get_instance();
global $rs;
$pages = $OBJ->db->fetchArray("SELECT *
FROM ".PX."media, ".PX."objects_prefs
WHERE media_ref_id = '$rs[id]'
AND obj_ref_type = 'exhibit'
AND obj_ref_type = media_obj_type
ORDER BY media_order ASC, media_id ASC");
if (!$pages) return $rs['content'];
$s = ''; $a = ''; $w = 0;
$this->final_img_container = ($rs['content'] != '') ? ($this->text_padding_right + $this->text_width + $this->vid_padding_right + $this->vid_width) : 0;
foreach ($pages as $go)
{
$title = ($go['media_title'] == '') ? '' : "<div class='title'>" . $go['media_title'] . "</div>";
$title .= ($go['media_caption'] == '') ? '' : "<div class='caption'>" . $go['media_caption'] . "</div>";
$temp_x = $go['media_x'] + $this->picture_block_padding_right;
$this->final_img_container += ($go['media_x'] + $this->picture_block_padding_right);
$a .= "<div class='picture_holder' style='width: {$temp_x}px;'>\n";
$a .= "<div class='picture' style='width: {$go[media_x]}px;'>\n";
$a .= "<img src='" . BASEURL . GIMGS . "/$go[media_file]' width='$go[media_x]' height='$go[media_y]' alt='" . BASEURL . GIMGS . "/$go[media_file]' />\n";
$a .= "<div class='captioning'>$title</div>\n";
$a .= "</div>\n";
$a .= "</div>\n\n";
}
$s .= "<div class='text'><div class='scroller'><spa开发者_JS百科n><a href='javascript:void(0);' class='prev'>«</a></span><span class='title'><a href='javascript:void(0);' class='origin'><%title%></a></span><span><a href='javascript:void(0);' class='next'>»</a></span></div><div id='img-container'>\n";
if ($rs['content'] != '') $s .= "<div id='text'>" . $rs['content'] . "</div>\n";
$s .= $a;
$s .= "<div style='clear: left;'><!-- --></div>";
$s .= "</div></div>\n";
return $s;
}
function dynamicCSS()
{
return "#img-container { width: " . ($this->final_img_container + 1) . "px; }
#img-container #text { float: left; width: " . ($this->text_width + $this->text_padding_right) . "px; }
#img-container #text p { width: " . $this->text_width . "px; }
#img-container #vid { float: left; width: " . ($this->vid_width + $this->vid_padding_right) . "px; }
#img-container #vid p { width: " . $this->vid_width . "px; }
#img-container .picture_holder { float: left; }
#img-container .picture { /* padding-top: 10px; */ }
#img-container .captioning .title { margin-top: 12px; font-weight: bold; }
#img-container .captioning .caption { font-family:PerspectiveSansItalic;
font-size:11px; color: #444; padding-top: 10px;}";
}
}
Isn't it better to fix this with Javascript when the page is loaded?
Just find the div with id "vid" and add the right css to it. Something like:
$(function() {
$("div#vid").load(function() {
$(this).addClass("whateverclassyouwanttoadd");
})
}
I'm not a jquery guru, but I think this will solve your problem.
Just some sidenodes: I think it's better to keep your presentation seperated from your business logic. So work with stylesheets to markup your HTML and add classes to your HTML in your views/business logic.
Just my 2 cents
Good luck!
精彩评论