如何使用灯箱选项?

时间:2015-10-17 13:45:15

标签: javascript lightbox lightbox2

如何使用lightbox 2选项?如何包含在文件中?它无法在网站http://lokeshdhakar.com/projects/lightbox2/#options

上指定
<script>
    lightbox.option({
      'resizeDuration': 200,
      'wrapAround': true
    })
</script>


<a class="example-image-link" data-lightbox="example-set" href="pic.png">
  <img style="width: 100%" src="pic.png">
</a>

如何设置灯箱选项?

1 个答案:

答案 0 :(得分:0)

确保您同时包含lightbox.js AND lightbox.css样式表。

您还需要jQuery 1.7或更高版本(如Getting Started section of the Lightbox website的第4步所述)。您应该在灯箱脚本之前包含jQuery脚本。

此设置对我有用:

module Admin
  class SeminovosController < SuperAdminController
    before_action :set_seminovo, only: [:show, :edit, :update, :destroy]

    # GET /seminovos
    # GET /seminovos.json
    def index
      @seminovos = Seminovo.all
      @seminovo = Seminovo.new
      @seminovo.photos.build
      #expires_in 3.hours, :public => true, 'max-stale' => 0
    end

    # GET /seminovos/1
    # GET /seminovos/1.json
    def show
    end

    # GET /seminovos/new
    def new
      @seminovo = Seminovo.new
      @seminovo.photos.build
      @seminovo.photos
    end

    # GET /seminovos/1/edit
    def edit
      @seminovo.photos.build
      @seminovo.photos
    end

    # POST /seminovos
    # POST /seminovos.json
    def create
      #@seminovo = Seminovo.new(seminovo_params)

      respond_to do |format|
        @seminovo = Seminovo.new(seminovo_params)
        @seminovo.save
        format.html { redirect_to @seminovo }
        format.js

       # if @seminovo.save
       #   format.html { redirect_to @seminovo, notice: 'Seminovo was successfully created.' }
       #   format.json { render :show, status: :created, location: @seminovo }
       # else
       #   format.html { render :new }
       #   format.json { render json: @seminovo.errors, status: :unprocessable_entity }
       # end
      end
    end

    # PATCH/PUT /seminovos/1
    # PATCH/PUT /seminovos/1.json
    def update
      respond_to do |format|
        if @seminovo.update(seminovo_params)
          format.html { redirect_to @seminovo, notice: 'Seminovo was successfully updated.' }
          format.json { render :show, status: :ok, location: @seminovo }
        else
          format.html { render :edit }
          format.json { render json: @seminovo.errors, status: :unprocessable_entity }
        end
      end
    end

    # DELETE /seminovos/1
    # DELETE /seminovos/1.json
    def destroy
      @seminovo.destroy
      respond_to do |format|
        format.html { redirect_to seminovos_url, notice: 'Seminovo was successfully destroyed.' }
        format.json { head :no_content }
      end
    end

    private
      # Use callbacks to share common setup or constraints between actions.
      def set_seminovo
        @seminovo = Seminovo.friendly.find(params[:id])
      end

      # Never trust parameters from the scary internet, only allow the white list through.
      def seminovo_params
        params.require(:seminovo).permit(:name, :price, :marca_id, :tipo_id, :ano_modelo, 
                                         :portas, :km_rodados, :combustivel, :placa, :cor, :desc, 
                                         :video, :destaque, :photo_id, :slug, 

                                         photos_attributes: [ :id, :image, :image_uid, :image_name, :desc,
                                         :seminovos_id, :_destroy ])
      end
  end
end