Blame view

frontend/components/BgWidget.php 897 Bytes
4253cbec   root   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
  <?php
  namespace frontend\components;
  
  use Yii;
  use yii\base\Widget;
  use yii\helpers\Html;
  use yii\web\View;
  use common\models\Bg;
  
  class BgWidget extends Widget{
  	public $bg;
  	
  	public function init(){
  		parent::init();
                  $view = Yii::$app->getView();
                  $view->registerJs("
                      var heightR = $('.f').height();// высота экрана
                      var widthR = $(window).width();// ширина экрана
  
                      $('#bg').css({'height':heightR+100}); 
                  ", View::POS_READY, 'bg');                 
  		$this->bg = Bg::find()->orderBy('random()')->one();
  	}
  	
  	public function run(){         
  		return '<a id="bg" style="width:100%;height:100%;position:absolute;z-index:-1;background: url(/storage/bg/'.$this->bg->image.') center top no-repeat;" href="'.$this->bg->url.'" title="'.$this->bg->title.'"></a>
  ';
  	}
  }
  ?>